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

[FEAT] implement spacy models #143

Merged
merged 21 commits into from
Apr 18, 2023
Merged

[FEAT] implement spacy models #143

merged 21 commits into from
Apr 18, 2023

Conversation

isabelizimm
Copy link
Contributor

closes #121

@isabelizimm
Copy link
Contributor Author

isabelizimm commented Jan 6, 2023

~~at this state: figuring out how to handle non-serializable data types. this is implementing an interface to the .predict() methods on the Pipeline spaCy objects. Tests are not passing since spaCy requires a spacy.tokens.Doc object to make a prediction, which needs to be converted to json before POSTed to API endpoint. ~~

I could see that other frameworks have similar specific format. It might be useful to make the predict function single dispatch and then be able to register new data types in the spacy.py file.

Spacy can be pickled! Updated from predict() method on spaCy Pipelines to the nlp object

@isabelizimm isabelizimm changed the title wip: implement spacy models [FEAT] implement spacy models Mar 27, 2023
@isabelizimm isabelizimm marked this pull request as ready for review April 7, 2023 13:24
@isabelizimm isabelizimm added this to the v0.2.1 milestone Apr 7, 2023

input_data = api_data_to_frame(input_data)

for doc in self.model.pipe(input_data.iloc[:, 0]):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prototype will enforce 1 column, and this will select that column (regardless of name)

Docs on using spacy's pipe functionality on batch prediction https://spacy.io/api/language#pipe

): # is dict, more than one key
raise ValueError("Spacy prototype data must dictionary with 1 key")

prototype = vetiver_create_prototype(self.prototype_data)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will allow for no-prototype deployments. The column of text will come in as a list, and api_data_to_frame will transform to a DataFrame for predictions.

vetiver/handlers/spacy.py Outdated Show resolved Hide resolved
Copy link
Member

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

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

This worked well for me and looks good! 👍 I have two additional thoughts:

  • (do now in this PR) can you update the README to include spaCy now?
  • (let's think on this for future) how should we surface some model-specific documentation now that the number of supported models is growing?

@isabelizimm
Copy link
Contributor Author

This worked well for me and looks good! 👍 I have two additional thoughts:

  • (do now in this PR) can you update the README to include spaCy now?

Added!

  • (let's think on this for future) how should we surface some model-specific documentation now that the number of supported models is growing?

That sounds like a great idea. Off the bat, the model handlers are shown in the docs. It might be advantageous to add examples of each model in the examples/ directory, in docstrings, or both.

@isabelizimm isabelizimm merged commit 152dd6f into main Apr 18, 2023
@isabelizimm isabelizimm deleted the spacy branch April 18, 2023 21:53
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.

support spacy models
2 participants