Instructions to use openfoodfacts/spellcheck-mistral-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openfoodfacts/spellcheck-mistral-7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openfoodfacts/spellcheck-mistral-7b")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openfoodfacts/spellcheck-mistral-7b") model = AutoModelForCausalLM.from_pretrained("openfoodfacts/spellcheck-mistral-7b", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openfoodfacts/spellcheck-mistral-7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openfoodfacts/spellcheck-mistral-7b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openfoodfacts/spellcheck-mistral-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/openfoodfacts/spellcheck-mistral-7b
- SGLang
How to use openfoodfacts/spellcheck-mistral-7b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "openfoodfacts/spellcheck-mistral-7b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openfoodfacts/spellcheck-mistral-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "openfoodfacts/spellcheck-mistral-7b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openfoodfacts/spellcheck-mistral-7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use openfoodfacts/spellcheck-mistral-7b with Docker Model Runner:
docker model run hf.co/openfoodfacts/spellcheck-mistral-7b
Open Food Facts - Ingredients spellcheck model
When a product is added to the database, all its details, such as allergens, additives, or nutritional values, are either wrote down by the contributor, or automatically extracted from the product pictures using OCR.
However, it often happens the information extracted by OCR contains typos and errors due to bad quality pictures: low-definition, curved product, light reflection, etc...
To solve this problem, we developed an Ingredient Spellcheck 🍊, a model capable of correcting typos in a list of ingredients following a defined guideline. The model, based on [Mistral-7B-v0.3], was fine-tuned on thousand of corrected lists of ingredients extracted from the database.
Model Details
Model Description
The Open Food Facts Ingredients Spellcheck is a version of Mistral-7B-v0.3 fine-tuned on thousands of corrected list of ingredients extracted from the OFF database.
The training dataset, with the evaluation benchmark are available in the Open Food Facts HF repository:
- Training dataset: https://huggingface.co/datasets/openfoodfacts/spellcheck-dataset
- Evaluation benchmark: https://huggingface.co/datasets/openfoodfacts/spellcheck-benchmark
The project is currently in development. You can find it in the Open Food Facts Github repo.
A demo of this model is also available in HF Spaces.
- Repository: https://github.com/openfoodfacts/openfoodfacts-ai/tree/develop/spellcheck
- Demo: https://huggingface.co/spaces/jeremyarancio/ingredients-spellcheck
Uses
This model takes a list of ingredients of a product as input and returns the correction.
It follows a spellcheck guideline, which was used to build the training and evaluation datasets. You can find this guideline in the Spellcheck project README.
To respect the training process, the input list of ingredients needs to be embedded into the following prompt:
def prepare_instruction(text: str) -> str:
"""Prepare instruction prompt for fine-tuning and inference.
Identical to instruction during training.
Args:
text (str): List of ingredients
Returns:
str: Instruction.
"""
instruction = (
"###Correct the list of ingredients:\n"
+ text
+ "\n\n###Correction:\n"
)
return instruction
Training Details
The model training informations are available in the CometML Experiment Tracker, along the other experimentations.
The model was trained on AWS Sagemaker using an ml.g5.2xlarge instance for 3 epochs.
Evaluation
The model is evaluated on the benchmark using a custom evaluation algorithm.
In short, lists of ingredients are separated into 3 parts: original, reference, prediction. Using a sequence alignement algorithm between respectively original-reference and original-*prediction, we are able to tell which token were supposed to be corrected, and which one was actually corrected. This leads to a correction Precision and Recall.
The complete explanation of the algorithm is available in the Spellchech README.
Metrics:
- Correction precision: 0.67
- Correction recall: 0.62
- Localisation precision: 0.75
- Localisation recall: 0.69
Additional links:
- Open Food Facts website: https://world.openfoodfacts.org/discover
- Open Food Facts Github: https://github.com/openfoodfacts
- Downloads last month
- 19