| | --- |
| | license: apache-2.0 |
| | tags: |
| | - setfit |
| | - sentence-transformers |
| | - text-classification |
| | pipeline_tag: text-classification |
| | language: |
| | - es |
| | --- |
| | |
| | # mhammadkhan/negation-categories-classifier |
| |
|
| | This is a [SetFit model](https://github.com/huggingface/setfit) that can be used for text classification. The model has been trained using an efficient few-shot learning technique that involves: |
| |
|
| | 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning. |
| | 2. Training a classification head with features from the fine-tuned Sentence Transformer. |
| |
|
| | ## Usage |
| |
|
| | To use this model for inference, first install the SetFit library: |
| |
|
| | ```bash |
| | python -m pip install setfit |
| | ``` |
| |
|
| | You can then run inference as follows: |
| |
|
| | ```python |
| | from setfit import SetFitModel |
| | |
| | model = SetFitModel.from_pretrained("mhammadkhan/negation-categories-classifier") |
| | |
| | # Define category labels |
| | labels = {0: "dairy-free", 1: "gluten-free", 2: "nut-free", 3: "soy-free", 4: "vegan"} |
| | |
| | # Define input recipes |
| | recipes = [ |
| | {"text": "Tacos de Coliflor Vegana", "ingredients":["cauliflower", "taco seasoning", "corn tortillas", "avocado", "salsa", "cilantro", "lime wedges"]}, |
| | {"text": "Pulpo a la Gallega Sin Gluten", "ingredients":["octopus", "potatoes", "paprika", "olive oil", "salt"]}, |
| | {"text": "Creamy Tomato Soup", "ingredients":["tomatoes", "vegetable broth", "onion", "garlic", "coconut milk"]}, |
| | {"text": "Chicken Alfredo Pasta", "ingredients":["chicken breast", "pasta", "broccoli", "mushrooms", "cashew cream"]}, |
| | {"text": "Cheesy Broccoli Casserole", "ingredients":["broccoli", "almond milk", "nutritional yeast", "gluten-free breadcrumbs"]}, |
| | {"text": "Gluten-Free Pizza", "ingredients":["gluten-free pizza crust", "tomato sauce", "mozzarella cheese", "mushrooms", "bell peppers"]}, |
| | {"text": "Quinoa Salad with Roasted Vegetables", "ingredients":["quinoa", "roasted sweet potato", "roasted Brussels sprouts", "dried cranberries", "almonds"]}, |
| | {"text": "Gluten-Free Chocolate Chip Cookies", "ingredients":["gluten-free flour", "brown sugar", "baking soda", "chocolate chips", "coconut oil"]}, |
| | {"text": "Chicken Satay Skewers", "ingredients":["chicken breast", "coconut milk", "peanut butter", "soy sauce", "lime juice"]}, |
| | {"text": "Pesto Pasta Salad", "ingredients":["pasta", "basil", "parmesan cheese", "pine nuts", "olive oil"]}, |
| | {"text": "Maple-Glazed Salmon", "ingredients":["salmon", "maple syrup", "pecans", "butter", "garlic"]}, |
| | {"text": "Beef and Broccoli Stir-Fry", "ingredients":["beef sirloin", "broccoli", "carrots", "garlic", "ginger", "cornstarch"]}, |
| | {"text": "Creamy Mushroom Soup", "ingredients":["mushrooms", "vegetable broth", "onion", "garlic", "cashew cream"]}, |
| | {"text": "Lemon-Garlic Roasted Chicken", "ingredients":["chicken thighs", "lemon juice", "garlic", "olive oil", "rosemary"]}, |
| | {"text": "Vegan Lasagna", "ingredients":["lasagna noodles", "tofu ricotta", "marinara sauce", "spinach", "mushrooms"]}, |
| | {"text": "Chickpea Curry", "ingredients":["chickpeas", "coconut milk", "tomatoes", "spinach", "curry powder"]}, |
| | {"text": "Vegan Banana Bread", "ingredients":["flour", "bananas", "sugar", "baking powder", "almond milk"]}, |
| | ] |
| | |
| | # Run inference |
| | preds = model(recipes) |
| | print(preds) |
| | # Map integer predictions to category labels |
| | preds = [labels[pred.item()] for pred in preds] |
| | |
| | print(preds) |
| | ``` |
| |
|
| | ## BibTeX entry and citation info |
| |
|
| | ```bibtex |
| | @article{https://doi.org/10.48550/arxiv.2209.11055, |
| | doi = {10.48550/ARXIV.2209.11055}, |
| | url = {https://arxiv.org/abs/2209.11055}, |
| | author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren}, |
| | keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences}, |
| | title = {Efficient Few-Shot Learning Without Prompts}, |
| | publisher = {arXiv}, |
| | year = {2022}, |
| | copyright = {Creative Commons Attribution 4.0 International} |
| | } |
| | ``` |