Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RasaModelData can handle 4D Tensors #6833

Merged
merged 30 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6d21133
Merge branch 'master' into 4d-tensors
tabergma Sep 24, 2020
4d8d6b8
handle 4d dense features
tabergma Sep 25, 2020
33e1efa
padding for dense and sparse works
tabergma Sep 25, 2020
1ba9791
update RasaModelData
tabergma Sep 29, 2020
3a720a8
update RasaModelData tests
tabergma Sep 29, 2020
9f18a48
update shape of sparse tensors
tabergma Sep 29, 2020
0a29c64
update is_in_4d_format
tabergma Sep 29, 2020
22cbb02
Merge branch 'e2e' into 4d-tensors
tabergma Sep 29, 2020
61350d1
set eager back to False
tabergma Sep 29, 2020
e8b55b4
fix code quality issues
tabergma Sep 29, 2020
3690aee
formatting
tabergma Sep 29, 2020
388b18a
Merge branch 'e2e' into 4d-tensors
tabergma Sep 30, 2020
d4a0fbe
fix type issues
tabergma Sep 30, 2020
48c9bd0
refactoring
tabergma Sep 30, 2020
656eb70
update types
tabergma Sep 30, 2020
55a1759
formatting
tabergma Sep 30, 2020
a947c9b
fix type issue
tabergma Sep 30, 2020
3540707
subclass numpy array
tabergma Sep 30, 2020
0f0c873
explicit specify number_of_dimensions
tabergma Oct 1, 2020
fb29d2c
clean up
tabergma Oct 1, 2020
16b6787
training is working again
tabergma Oct 1, 2020
59d594e
rename feature_dimension to units
tabergma Oct 1, 2020
68b5465
reset default eager values
tabergma Oct 1, 2020
a46f277
update comments
tabergma Oct 1, 2020
ad1a34d
refactoring
tabergma Oct 1, 2020
bb8de45
fix type issue
tabergma Oct 1, 2020
053247e
fix types
tabergma Oct 5, 2020
8018f83
review comments
tabergma Oct 6, 2020
9a5cbf0
Merge branch 'e2e' into 4d-tensors
tabergma Oct 6, 2020
8da6f58
formatting
tabergma Oct 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions rasa/utils/tensorflow/model_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def __new__(

return feature_array

def __init__(self, input_array: Any, number_of_dimensions: int, **kwargs):
# Needed in order to avoid 'Invalid keyword argument number_of_dimensions to function FeatureArray.__init__ '
super().__init__(**kwargs)
self.number_of_dimensions = number_of_dimensions

def __array_finalize__(self, obj: Any) -> None:
if obj is None:
return
Expand Down Expand Up @@ -152,7 +157,7 @@ def _validate_number_of_dimensions(
f"array: {input_array}."
)

def get_shape_type_info(self) -> Tuple[List[Tuple], List[Tuple]]:
def get_shape_type_info(self) -> Tuple[List, List]:
tabergma marked this conversation as resolved.
Show resolved Hide resolved
"""Returns the shape and type information needed to convert this feature array into tensors.

Returns:
Expand Down Expand Up @@ -183,7 +188,7 @@ def get_shape_type_info(self) -> Tuple[List[Tuple], List[Tuple]]:
return [(None, None, None, self.units)], [tf.float32]

return [], []


class FeatureSignature(NamedTuple):
"""Stores the shape, the type (sparse vs dense), and the number of dimensions of features."""
Expand Down
6 changes: 3 additions & 3 deletions rasa/utils/tensorflow/model_data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def convert_to_data_format(
List[List[Dict[Text, List["Features"]]]], List[Dict[Text, List["Features"]]]
],
zero_state_features: Optional[Dict[Text, List["Features"]]] = None,
) -> Tuple[Data, Optional[Dict[Text, List[FeatureArray]]]]:
) -> Tuple[Data, Optional[Dict[Text, List["Features"]]]]:
"""Converts the input into "Data" format.

Args:
Expand Down Expand Up @@ -186,8 +186,8 @@ def _features_for_attribute(
tracker_features, zero_state_features[attribute]
)

sparse_features = defaultdict(list)
dense_features = defaultdict(list)
sparse_features = defaultdict()
dense_features = defaultdict()
tabergma marked this conversation as resolved.
Show resolved Hide resolved

# vstack serves as removing dimension in case we are not dealing with a sequence
for key, values in _sparse_features.items():
Expand Down