How to create a nlp object with a dict instead of a string? #10129
-
The typical way of creating a nlp and doc object is:
Is it possible that my input is not a str, but a dict like:
Is it possible that a doc can created like:
The reason is that, my custom component needs to access other fields of the input, beyond the usual 'text' field. Please advise ideas if this is possible. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You can't exactly pass a dict as input, but in 3.2 we added a feature for exactly this kind of use case such that you can use a Doc as input to a pipeline (pipeline = nlp object). So what you can do is have a minimal pipeline that does maybe just tokenization, then add your data to the Doc as underscore attributes, and then pass that to another pipeline with your custom components. |
Beta Was this translation helpful? Give feedback.
-
Good to know the new features. What about the component_cfg = {} argument? Can I access this argument from a nlp object? |
Beta Was this translation helpful? Give feedback.
You can't exactly pass a dict as input, but in 3.2 we added a feature for exactly this kind of use case such that you can use a Doc as input to a pipeline (pipeline = nlp object). So what you can do is have a minimal pipeline that does maybe just tokenization, then add your data to the Doc as underscore attributes, and then pass that to another pipeline with your custom components.