Skip to content

WIP: generator accepts NdArray attribute #575

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

Merged
merged 45 commits into from
Jan 13, 2022
Merged

WIP: generator accepts NdArray attribute #575

merged 45 commits into from
Jan 13, 2022

Conversation

zhanyuanucb
Copy link
Collaborator

@zhanyuanucb zhanyuanucb commented Dec 20, 2021

This PR fixes #567.

Description of changes

  • In ontology_code_const.py:

    • Add “NdArray” to COMPOSITE

    • Add “shape” and “dtype” to SchemaKeyWords

  • In ontology_code_generator.py:

    • modify parse_property to handle att_type == “NdArray”
    • define parse_ndarray to parse ndarray attributes:
      • ndarray_value_type
    • return a NdArrayProperty
  • In code_generation_objects.py

    • add NdArrayProperty
  • In forte.data.ontology.core.py

    • add FNdArray that wraps a numpy ndarray and store related properties like dtype and shape
  • validation_schema.json

    • Add schema for NdArray attribute

Possible influences of this PR.

Describe what are the possible side-effects of the code change.

Test Conducted

  • tests/forte/data/ontology/ontology_code_generator_test.py
    • test generated code for sample Entry containing NdArray attribute
  • tests/forte/data/ontology/ndarray_attribute_test.py:
    • Test serialization
    • Test setting array property

@codecov
Copy link

codecov bot commented Dec 20, 2021

Codecov Report

Merging #575 (7599c13) into master (ab5248e) will increase coverage by 0.22%.
The diff coverage is 96.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #575      +/-   ##
==========================================
+ Coverage   79.86%   80.09%   +0.22%     
==========================================
  Files         229      231       +2     
  Lines       16239    16452     +213     
==========================================
+ Hits        12970    13177     +207     
- Misses       3269     3275       +6     
Impacted Files Coverage Δ
forte/data/ontology/code_generation_objects.py 92.67% <84.21%> (-0.39%) ⬇️
...ests/forte/data/ontology/ndarray_attribute_test.py 94.66% <94.66%> (ø)
forte/data/ontology/core.py 84.06% <100.00%> (+1.83%) ⬆️
forte/data/ontology/ontology_code_const.py 100.00% <100.00%> (ø)
forte/data/ontology/ontology_code_generator.py 90.09% <100.00%> (+0.37%) ⬆️
...orte/data/ontology/ontology_code_generator_test.py 100.00% <100.00%> (ø)
...data/ontology/test_outputs/ft/onto/test_ndarray.py 100.00% <100.00%> (ø)
forte/data/base_pack.py 77.77% <0.00%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab5248e...7599c13. Read the comment docs.

@hunterhector hunterhector marked this pull request as draft December 22, 2021 01:20
@zhanyuanucb zhanyuanucb marked this pull request as ready for review January 5, 2022 18:33
Copy link
Member

@hunterhector hunterhector left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks very good, only a few small comments.

@@ -382,6 +383,45 @@ def to_field_value(self):
return self.name


class NdArrayProperty(Property):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need some docstring for the class. I understand that many other classes in this file don't have that, but that's a historical mistake, let's add docstring as much as possible for future code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

@@ -95,6 +95,14 @@
"value_type": {
"description": "Item type for the case of Dice attributes",
"type": "string"
},
"ndarray_dtype": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have some tests to validate a JSON spec with this schema, hopefully, both success and failure cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test against invalid shape.
Do you think we can rely on numpy to validate dtype?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be great if schema can check the possible dtype values. Since this is done without actually running the code, while numpy validation happens late at run time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good.
I've added more tests against dtype and shape

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the validation looks awesome, and thanks for the tests

@hunterhector hunterhector merged commit 45b9551 into asyml:master Jan 13, 2022
@zhanyuanucb zhanyuanucb deleted the issue#567 branch January 13, 2022 19:47
mylibrar pushed a commit to mylibrar/forte that referenced this pull request Jan 14, 2022
* added static methods to infer pack type

* added unit tests for datapack type inference.

* fixed issue#558

* fixed black: forte/data/selector.py

* fixed import-outside-toplevel

* WIP: waiting for ndarray supported

* Ndarray -> ndarray

* values -> value

* added ndarray to SUPPORTED_PRIMITIVES

* WIP: generator accepts NdArray attribute

* remove breakpoints

* fixed None -> "None"

* WIP: designing NdArrayProperty

* WIP: ndarray_size -> ndarray_shape

* fixed lint

* fixed lint

* added ndarray property test cases

* removed irrelevant onto spec

* fixed lint

* fixed lint

* fixed black

* fixed description

* added FNdArray, a wrapper class for NdArray metric

* handle None dtype

* removed Optional typing

* fixed description

* added unit tests for ndarray attribute

* fixed black

* added doc string and more tests

* fixed type

* added reference to np.ndarray

* added unit tests for ndarray attribute against dtype, shape, and warning

Co-authored-by: Zhanyuan Zhang <zhanyuan.zhang@petuum.com>
mylibrar pushed a commit to mylibrar/forte that referenced this pull request Jan 14, 2022
* added static methods to infer pack type

* added unit tests for datapack type inference.

* fixed issue#558

* fixed black: forte/data/selector.py

* fixed import-outside-toplevel

* WIP: waiting for ndarray supported

* Ndarray -> ndarray

* values -> value

* added ndarray to SUPPORTED_PRIMITIVES

* WIP: generator accepts NdArray attribute

* remove breakpoints

* fixed None -> "None"

* WIP: designing NdArrayProperty

* WIP: ndarray_size -> ndarray_shape

* fixed lint

* fixed lint

* added ndarray property test cases

* removed irrelevant onto spec

* fixed lint

* fixed lint

* fixed black

* fixed description

* added FNdArray, a wrapper class for NdArray metric

* handle None dtype

* removed Optional typing

* fixed description

* added unit tests for ndarray attribute

* fixed black

* added doc string and more tests

* fixed type

* added reference to np.ndarray

* added unit tests for ndarray attribute against dtype, shape, and warning

Co-authored-by: Zhanyuan Zhang <zhanyuan.zhang@petuum.com>
mylibrar pushed a commit to mylibrar/forte that referenced this pull request Jan 14, 2022
* added static methods to infer pack type

* added unit tests for datapack type inference.

* fixed issue#558

* fixed black: forte/data/selector.py

* fixed import-outside-toplevel

* WIP: waiting for ndarray supported

* Ndarray -> ndarray

* values -> value

* added ndarray to SUPPORTED_PRIMITIVES

* WIP: generator accepts NdArray attribute

* remove breakpoints

* fixed None -> "None"

* WIP: designing NdArrayProperty

* WIP: ndarray_size -> ndarray_shape

* fixed lint

* fixed lint

* added ndarray property test cases

* removed irrelevant onto spec

* fixed lint

* fixed lint

* fixed black

* fixed description

* added FNdArray, a wrapper class for NdArray metric

* handle None dtype

* removed Optional typing

* fixed description

* added unit tests for ndarray attribute

* fixed black

* added doc string and more tests

* fixed type

* added reference to np.ndarray

* added unit tests for ndarray attribute against dtype, shape, and warning

Co-authored-by: Zhanyuan Zhang <zhanyuan.zhang@petuum.com>
mylibrar pushed a commit to mylibrar/forte that referenced this pull request Jan 14, 2022
* added static methods to infer pack type

* added unit tests for datapack type inference.

* fixed issue#558

* fixed black: forte/data/selector.py

* fixed import-outside-toplevel

* WIP: waiting for ndarray supported

* Ndarray -> ndarray

* values -> value

* added ndarray to SUPPORTED_PRIMITIVES

* WIP: generator accepts NdArray attribute

* remove breakpoints

* fixed None -> "None"

* WIP: designing NdArrayProperty

* WIP: ndarray_size -> ndarray_shape

* fixed lint

* fixed lint

* added ndarray property test cases

* removed irrelevant onto spec

* fixed lint

* fixed lint

* fixed black

* fixed description

* added FNdArray, a wrapper class for NdArray metric

* handle None dtype

* removed Optional typing

* fixed description

* added unit tests for ndarray attribute

* fixed black

* added doc string and more tests

* fixed type

* added reference to np.ndarray

* added unit tests for ndarray attribute against dtype, shape, and warning

Co-authored-by: Zhanyuan Zhang <zhanyuan.zhang@petuum.com>
hunterhector pushed a commit that referenced this pull request Jan 20, 2022
* Add AudioAnnotation entry to ontology system

* WIP: generator accepts NdArray attribute (#575)

* added static methods to infer pack type

* added unit tests for datapack type inference.

* fixed issue#558

* fixed black: forte/data/selector.py

* fixed import-outside-toplevel

* WIP: waiting for ndarray supported

* Ndarray -> ndarray

* values -> value

* added ndarray to SUPPORTED_PRIMITIVES

* WIP: generator accepts NdArray attribute

* remove breakpoints

* fixed None -> "None"

* WIP: designing NdArrayProperty

* WIP: ndarray_size -> ndarray_shape

* fixed lint

* fixed lint

* added ndarray property test cases

* removed irrelevant onto spec

* fixed lint

* fixed lint

* fixed black

* fixed description

* added FNdArray, a wrapper class for NdArray metric

* handle None dtype

* removed Optional typing

* fixed description

* added unit tests for ndarray attribute

* fixed black

* added doc string and more tests

* fixed type

* added reference to np.ndarray

* added unit tests for ndarray attribute against dtype, shape, and warning

Co-authored-by: Zhanyuan Zhang <zhanyuan.zhang@petuum.com>

* Resolve comments

* Fix confusing types of range_annotation

* Add test case for AudioAnnotation

Co-authored-by: Suqi Sun <suqi.sun@petuum.com>
Co-authored-by: Zhanyuan Zhang <32000378+zhanyuanucb@users.noreply.github.com>
Co-authored-by: Zhanyuan Zhang <zhanyuan.zhang@petuum.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ontology generator allows ndarray attribute
2 participants