Forkulous/usda-retrieve-rerank
Viewer • Updated • 9.97k • 47
How to use Forkulous/be-forkulous with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Forkulous/be-forkulous")
sentences = [
"ingredient: 1 onion large, cut into 1/2-inch dice",
"usda: Onions, welsh, raw",
"usda: Pretzels, soft, ready-to-eat, unsalted, buttered",
"usda: Carrots, raw, salad"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]This is the main embedding model for Forkulous, a free-as-in-freedom API for turning unstructured recipe data into nutrient information.
This model accepts either unparsed freetext ingredient lines and descriptions from USDA FoodDataCentral and outputs a vector in a 384-dimensional vector space.
This is not a model for sequence/token classification of single ingredient lines.
This is a sentence-transformers model finetuned from sentence-transformers/all-MiniLM-L6-v2. It maps sentences & paragraphs to a 384-dimensional dense vector space and can be used for retrieval.
SentenceTransformer(
(0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'BertModel'})
(1): Pooling({'embedding_dimension': 384, 'pooling_mode': 'mean', 'include_prompt': True})
(2): Normalize({})
)
First install the Sentence Transformers library:
pip install -U sentence-transformers
Then you can load this model and run inference.
from sentence_transformers import SentenceTransformer
# Download from the 🤗 Hub
model = SentenceTransformer("Forkulous/be-forkulous")
# Run inference
queries = [
'ingredient: 6 tablespoons mascarpone cheese softened to room temperature',
]
documents = [
'usda: Cheese, tilsit',
'usda: Sauce, NFS',
'usda: Veal, variety meats and by-products, thymus, cooked, braised',
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# [1, 384] [3, 384]
# Get the similarity scores for the embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[0.6883, 0.4792, 0.2840]])
EmbeddingSimilarityEvaluator| Metric | Value |
|---|---|
| pearson_cosine | 0.8612 |
| spearman_cosine | 0.8619 |
query, document, and score| query | document | score | |
|---|---|---|---|
| type | string | string | float |
| modality | text | text | |
| details |
|
|
|
| query | document | score |
|---|---|---|
ingredient: 2/3 cup potato starch or corn starch |
usda: FLOUR, CORN, YELLOW (FINE MEAL) (ENRICHED) |
0.4 |
ingredient: 2 heads butter lettuce chopped |
usda: Lettuce, for use on a sandwich |
1.0 |
ingredient: whipped cream or ice cream, for serving |
usda: Beef with cream or white sauce |
0.0 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
query, document, and score| query | document | score | |
|---|---|---|---|
| type | string | string | float |
| modality | text | text | |
| details |
|
|
|
| query | document | score |
|---|---|---|
ingredient: 2/3 cup dark brown sugar packed soft |
usda: Cherries, dark red, sweet, raw |
0.0 |
ingredient: 1/4 granulated sugar I used raw |
usda: C&H Granulated White Sugar (OK1) - NFY040Y38 |
0.9 |
ingredient: 1 cup yellow squash diced |
usda: Squash, yellow, raw |
1.0 |
CoSENTLoss with these parameters:{
"scale": 20.0,
"similarity_fct": "pairwise_cos_sim"
}
per_device_train_batch_size: 32num_train_epochs: 5lr_scheduler_type: cosinewarmup_steps: 122.578125per_device_eval_batch_size: 32load_best_model_at_end: Trueper_device_train_batch_size: 32num_train_epochs: 5max_steps: -1learning_rate: 5e-05lr_scheduler_type: cosinelr_scheduler_kwargs: Nonewarmup_steps: 122.578125optim: adamw_torch_fusedoptim_args: Noneweight_decay: 0.0adam_beta1: 0.9adam_beta2: 0.999adam_epsilon: 1e-08optim_target_modules: Nonegradient_accumulation_steps: 1average_tokens_across_devices: Truemax_grad_norm: 1.0label_smoothing_factor: 0.0bf16: Falsefp16: Falsebf16_full_eval: Falsefp16_full_eval: Falsetf32: Nonegradient_checkpointing: Falsegradient_checkpointing_kwargs: Nonetorch_compile: Falsetorch_compile_backend: Nonetorch_compile_mode: Noneuse_liger_kernel: Falseliger_kernel_config: Noneuse_cache: Falseneftune_noise_alpha: Nonetorch_empty_cache_steps: Noneauto_find_batch_size: Falselog_on_each_node: Truelogging_nan_inf_filter: Trueinclude_num_input_tokens_seen: nolog_level: passivelog_level_replica: warningdisable_tqdm: Falseproject: huggingfacetrackio_space_id: Nonetrackio_bucket_id: Nonetrackio_static_space_id: Noneper_device_eval_batch_size: 32prediction_loss_only: Trueeval_on_start: Falseeval_do_concat_batches: Trueeval_use_gather_object: Falseeval_accumulation_steps: Noneinclude_for_metrics: []batch_eval_metrics: Falsesave_only_model: Falsesave_on_each_node: Falseenable_jit_checkpoint: Falsepush_to_hub: Falsehub_private_repo: Nonehub_model_id: Forkulous/be-forkuloushub_strategy: every_savehub_always_push: Falsehub_revision: Noneload_best_model_at_end: Trueignore_data_skip: Falserestore_callback_states_from_checkpoint: Falsefull_determinism: Falseseed: 42data_seed: Noneuse_cpu: Falseaccelerator_config: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}parallelism_config: Nonedataloader_drop_last: Falsedataloader_num_workers: 0dataloader_pin_memory: Truedataloader_persistent_workers: Falsedataloader_prefetch_factor: Nonedataloader_multiprocessing_context: Nonedataloader_in_order: Trueremove_unused_columns: Truelabel_names: Nonetrain_sampling_strategy: randomlength_column_name: lengthddp_find_unused_parameters: Noneddp_bucket_cap_mb: Noneddp_broadcast_buffers: Falseddp_static_graph: Noneddp_backend: Noneddp_timeout: 1800fsdp: Nonefsdp_config: Nonedeepspeed: Nonedebug: []skip_memory_metrics: Truedo_predict: Falseresume_from_checkpoint: Nonelocal_rank: -1prompts: Nonebatch_sampler: batch_samplermulti_dataset_batch_sampler: proportionalrouter_mapping: {}learning_rate_mapping: {}warmup_ratio: None| Epoch | Step | Training Loss | Validation Loss | spearman_cosine |
|---|---|---|---|---|
| 0.0407 | 10 | 7.8560 | - | - |
| 0.0813 | 20 | 6.6645 | - | - |
| 0.1220 | 30 | 6.6995 | - | - |
| 0.1626 | 40 | 6.3168 | - | - |
| 0.2033 | 50 | 6.0008 | - | - |
| 0.2439 | 60 | 5.6803 | - | - |
| 0.2846 | 70 | 5.4944 | - | - |
| 0.3252 | 80 | 5.5124 | - | - |
| 0.3659 | 90 | 5.5266 | - | - |
| 0.4065 | 100 | 5.4270 | - | - |
| 0.4472 | 110 | 5.5078 | - | - |
| 0.4878 | 120 | 5.4180 | - | - |
| 0.4959 | 122 | - | 5.3326 | 0.7899 |
| 0.5285 | 130 | 5.2544 | - | - |
| 0.5691 | 140 | 5.3673 | - | - |
| 0.6098 | 150 | 5.3187 | - | - |
| 0.6504 | 160 | 5.2386 | - | - |
| 0.6911 | 170 | 5.2490 | - | - |
| 0.7317 | 180 | 5.4214 | - | - |
| 0.7724 | 190 | 5.1935 | - | - |
| 0.8130 | 200 | 5.2074 | - | - |
| 0.8537 | 210 | 5.1898 | - | - |
| 0.8943 | 220 | 5.2349 | - | - |
| 0.9350 | 230 | 5.1351 | - | - |
| 0.9756 | 240 | 5.3108 | - | - |
| 0.9919 | 244 | - | 5.2236 | 0.8234 |
| 1.0163 | 250 | 4.8030 | - | - |
| 1.0569 | 260 | 4.8858 | - | - |
| 1.0976 | 270 | 5.0583 | - | - |
| 1.1382 | 280 | 4.8510 | - | - |
| 1.1789 | 290 | 4.9847 | - | - |
| 1.2195 | 300 | 4.8511 | - | - |
| 1.2602 | 310 | 5.0625 | - | - |
| 1.3008 | 320 | 4.9002 | - | - |
| 1.3415 | 330 | 4.8812 | - | - |
| 1.3821 | 340 | 4.8602 | - | - |
| 1.4228 | 350 | 4.9375 | - | - |
| 1.4634 | 360 | 5.1199 | - | - |
| 1.4878 | 366 | - | 5.2299 | 0.8481 |
| 1.5041 | 370 | 4.7782 | - | - |
| 1.5447 | 380 | 4.9243 | - | - |
| 1.5854 | 390 | 4.8123 | - | - |
| 1.6260 | 400 | 5.1224 | - | - |
| 1.6667 | 410 | 4.8130 | - | - |
| 1.7073 | 420 | 4.8003 | - | - |
| 1.7480 | 430 | 4.7271 | - | - |
| 1.7886 | 440 | 4.9549 | - | - |
| 1.8293 | 450 | 4.8807 | - | - |
| 1.8699 | 460 | 4.8482 | - | - |
| 1.9106 | 470 | 4.7049 | - | - |
| 1.9512 | 480 | 4.9837 | - | - |
| 1.9837 | 488 | - | 5.2740 | 0.8499 |
| 1.9919 | 490 | 4.9704 | - | - |
| 2.0325 | 500 | 4.2136 | - | - |
| 2.0732 | 510 | 4.3989 | - | - |
| 2.1138 | 520 | 4.6642 | - | - |
| 2.1545 | 530 | 4.6626 | - | - |
| 2.1951 | 540 | 4.7278 | - | - |
| 2.2358 | 550 | 4.5797 | - | - |
| 2.2764 | 560 | 4.4921 | - | - |
| 2.3171 | 570 | 4.5389 | - | - |
| 2.3577 | 580 | 4.5522 | - | - |
| 2.3984 | 590 | 4.3810 | - | - |
| 2.4390 | 600 | 4.4543 | - | - |
| 2.4797 | 610 | 4.4910 | 5.7227 | 0.8565 |
| 2.5203 | 620 | 4.4647 | - | - |
| 2.5610 | 630 | 4.5019 | - | - |
| 2.6016 | 640 | 5.1985 | - | - |
| 2.6423 | 650 | 4.5147 | - | - |
| 2.6829 | 660 | 4.3910 | - | - |
| 2.7236 | 670 | 4.3696 | - | - |
| 2.7642 | 680 | 4.4902 | - | - |
| 2.8049 | 690 | 4.8663 | - | - |
| 2.8455 | 700 | 4.5024 | - | - |
| 2.8862 | 710 | 4.6200 | - | - |
| 2.9268 | 720 | 4.5397 | - | - |
| 2.9675 | 730 | 4.5980 | - | - |
| 2.9756 | 732 | - | 5.5092 | 0.8602 |
| 3.0081 | 740 | 4.1333 | - | - |
| 3.0488 | 750 | 4.1640 | - | - |
| 3.0894 | 760 | 4.3004 | - | - |
| 3.1301 | 770 | 4.3414 | - | - |
| 3.1707 | 780 | 4.5028 | - | - |
| 3.2114 | 790 | 4.1783 | - | - |
| 3.2520 | 800 | 4.2447 | - | - |
| 3.2927 | 810 | 4.1731 | - | - |
| 3.3333 | 820 | 4.2797 | - | - |
| 3.3740 | 830 | 4.4345 | - | - |
| 3.4146 | 840 | 4.1085 | - | - |
| 3.4553 | 850 | 4.2252 | - | - |
| 3.4715 | 854 | - | 5.8100 | 0.8581 |
| 3.4959 | 860 | 4.2567 | - | - |
| 3.5366 | 870 | 4.2262 | - | - |
| 3.5772 | 880 | 4.2609 | - | - |
| 3.6179 | 890 | 4.5412 | - | - |
| 3.6585 | 900 | 4.2727 | - | - |
| 3.6992 | 910 | 4.2478 | - | - |
| 3.7398 | 920 | 4.1876 | - | - |
| 3.7805 | 930 | 4.3053 | - | - |
| 3.8211 | 940 | 4.2070 | - | - |
| 3.8618 | 950 | 4.2778 | - | - |
| 3.9024 | 960 | 4.2651 | - | - |
| 3.9431 | 970 | 4.5292 | - | - |
| 3.9675 | 976 | - | 5.8038 | 0.8604 |
| 3.9837 | 980 | 4.2689 | - | - |
| 4.0244 | 990 | 3.5685 | - | - |
| 4.0650 | 1000 | 4.0194 | - | - |
| 4.1057 | 1010 | 4.0093 | - | - |
| 4.1463 | 1020 | 4.1102 | - | - |
| 4.1870 | 1030 | 3.9494 | - | - |
| 4.2276 | 1040 | 4.2017 | - | - |
| 4.2683 | 1050 | 4.0265 | - | - |
| 4.3089 | 1060 | 4.2574 | - | - |
| 4.3496 | 1070 | 4.4601 | - | - |
| 4.3902 | 1080 | 4.0986 | - | - |
| 4.4309 | 1090 | 4.1873 | - | - |
| 4.4634 | 1098 | - | 5.9042 | 0.8620 |
| 4.4715 | 1100 | 4.0357 | - | - |
| 4.5122 | 1110 | 3.9086 | - | - |
| 4.5528 | 1120 | 4.0057 | - | - |
| 4.5935 | 1130 | 4.2979 | - | - |
| 4.6341 | 1140 | 4.3391 | - | - |
| 4.6748 | 1150 | 3.9628 | - | - |
| 4.7154 | 1160 | 3.9963 | - | - |
| 4.7561 | 1170 | 4.1324 | - | - |
| 4.7967 | 1180 | 4.1531 | - | - |
| 4.8374 | 1190 | 3.9365 | - | - |
| 4.8780 | 1200 | 3.8198 | - | - |
| 4.9187 | 1210 | 4.0716 | - | - |
| 4.9593 | 1220 | 4.3199 | 5.9275 | 0.8619 |
| 5.0 | 1230 | 3.3747 | 5.9275 | 0.8619 |
@inproceedings{reimers-2019-sentence-bert,
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
author = "Reimers, Nils and Gurevych, Iryna",
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
month = "11",
year = "2019",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/1908.10084",
}
@article{10531646,
author={Huang, Xiang and Peng, Hao and Zou, Dongcheng and Liu, Zhiwei and Li, Jianxin and Liu, Kay and Wu, Jia and Su, Jianlin and Yu, Philip S.},
journal={IEEE/ACM Transactions on Audio, Speech, and Language Processing},
title={CoSENT: Consistent Sentence Embedding via Similarity Ranking},
year={2024},
doi={10.1109/TASLP.2024.3402087}
}
Base model
nreimers/MiniLM-L6-H384-uncased