--- license: mit base_model: BAAI/bge-large-en-v1.5 library_name: sentence-transformers pipeline_tag: sentence-similarity language: en tags: - sentence-transformers - hs-code - customs - tariff-classification - retrieval --- # hs-code-embedder-bge-large [BAAI/bge-large-en-v1.5](https://huggingface.co/BAAI/bge-large-en-v1.5), fine-tuned to match free-text product descriptions to UK Trade Tariff (HS/commodity code) reference entries. It's the retrieval model behind [hs-code-classifier](https://github.com/Jayden04260/hs-code-classifier). ## Usage Queries take bge's retrieval prefix; tariff entries are embedded as-is. ```python from sentence_transformers import SentenceTransformer model = SentenceTransformer("Jayden04260/hs-code-embedder-bge-large") prefix = "Represent this sentence for searching relevant passages: " q = model.encode([prefix + "wireless over-ear bluetooth headphones"], normalize_embeddings=True) docs = model.encode(["headphones, wireless", "bluetooth headset", "loudspeakers"], normalize_embeddings=True) print(q @ docs.T) ``` ## Training One epoch of contrastive training (MultipleNegativesRankingLoss, batch size 32, lr 1e-5) on ~14k pairs built from the UK Trade Tariff's public reference data: - a reference title paired with another reference title for the same commodity code; - a title paired with its heading's official nomenclature text; - a heading paired with its chapter text. Pairs come only from the training side of the project's train/held-out split. The evaluation sets below were never trained on. Script: [`train_embedder.py`](https://github.com/Jayden04260/hs-code-classifier/blob/main/train_embedder.py). ## Evaluation Top-1 accuracy using retrieval over ~10k UK tariff entries (cosine similarity, no re-ranking): | Test | all-MiniLM-L6-v2 + ms-marco re-ranker | untuned bge-large | **this model** | |---|---|---|---| | 500 held-out tariff titles: exact 10-digit code | 0.42 | 0.43 | **0.50** | | [HSCodeComp](https://huggingface.co/datasets/ATH-MaaS/HSCodeComp) real listings: 4-digit heading | 0.30 | 0.40 | **0.43** | | HSCodeComp: 2-digit chapter | 0.51 | 0.60 | **0.67** | HSCodeComp has 632 noisy marketplace listings classified by customs experts. Its codes are US codes, so only the internationally shared digits are compared. ## Limitations - English only. The model is tuned to the UK tariff's vocabulary; the first 6 digits of HS codes are international. - It suggests candidates for a human classifier to verify. It is not a customs ruling or legal advice. - HSCodeComp is mostly online consumer goods. Accuracy on bulk, industrial or chemical goods isn't measured there. Training data: UK Trade Tariff reference data (UK government, Open Government Licence v3.0).