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
How to add custom model into LIT? #599
Comments
See https://github.com/PAIR-code/lit/wiki/api.md#adding-models-and-data for defining your own model and dataset for use in LIT. You just need to write a Model and Dataset wrapper for your model and dataset. You can see and run code for a demo of the Stanza NER model in LIT here: https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/stanza_demo.py, with the model defined at https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/models/stanza_models.py |
Hi @jameswex any end to end code to add custom model and dataset for Roberta classification task. Or, are you planning to have one notebook(.ipynb) to get started with custom models and datasets. For beginners like me its little confusing. |
Hi @jameswex, how would I add an image classification model? I have a I get this error: Although I load the model in this way which is not similar to other examples since this is an image classification example.
|
@SpamDude15, as per #599, you should create a class for your model that inherits from One image model example can be found at https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/models/mobilenet.py |
@pratikchhapolika The LIT team does not have time to implement base classes for all models. If you're interested in RoBERTa, you can access the model from Hugging Face and implement your own As for data, LIT provides 2 of the 4 datasets (MNLI and SST-2) used in the RoBERTa paper out of the box. We don't have wrappers for SQuAD (on TFDS or HF Datasets) or RACE (on TFDS or HF Datasets) at this time. Once you have the For all commenters on this issue (@pratikchhapolika @SpamDude15 @abhibisht89), please remember that if you do implement these classes or demo modules, we would welcome contributions via PRs to incorporate them into the core LIT example. |
@jameswex I was wondering if there was a dynamic option to load models and datasets into LIT without having to write three different python files for loading, model, and dataset. |
@SpamDude15 not for models. There are too many modeling frameworks, and increasingly serving frameworks, for our research team to keep up with. Instead we've chosen to go the self-service route. Datasets are slightly easier. We are working on a generic dataset wrapper for TFDS, though I don't have an ETA for its release. That will likely act as a reference for creating a generic wrapper for the HF Datasets library, too, but again, no ETA on release. There is a Blank Slate demo that's easily forkable. Once you have the model and dataset classes, it should be as simple as importing them into the demo file and launching. |
@RyanMullins That's interesting, is there a way I can load in .ppm images? I looked through the datatypes on LIT, and there seems to be no option for ppm, so does that mean it isn't compatible? |
@SpamDude15 cant say I'm familiar with PPM images, but they seem like Pillow can read them. LIT passes around all images in base64 encoding (makes it easier to visualize in the UI, and allows flexibility for different input formats to models), so you can use Pillow to read and convert the PPM to base64 and then pass that to your model class or one of the existing image classification models in our examples. You can also add a new type If you work up a draft PR (in your own repo or a fork of LIT), I'm happy to review and provide some tips to get this working (in a way we could bring stuff upstream). |
@RyanMullins I got PPM images to work with LIT using base64 encoding, which was great, I was wondering if PNG could be loaded in the same way without having to use the defined datatype by LIT. image_file_path = Path(base_path+path_name) / row['Filename']
pil_image = PILImage.open(image_file_path)
image_str = image_utils.convert_pil_to_image_str(pil_image) |
Yup, that'll work for pretty much any image Pillow supports. The more specific |
how to add your own NER model and dataset into lit.
Any help ?
Thanks
The text was updated successfully, but these errors were encountered: