Sentence Similarity
sentence-transformers
Safetensors
xlm-roberta
product-similarity
product-embeddings
weak-supervision
text-embeddings-inference
Instructions to use beno-rohman/product-embedding-e5-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use beno-rohman/product-embedding-e5-base with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("beno-rohman/product-embedding-e5-base") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
Download training/scripts/sample_original.py from beno-rohman/product-embedding-e5-base: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/beno-rohman/product-embedding-e5-base/resolve/main/training/scripts/sample_original.py
- Command line
-
hf download hf://beno-rohman/product-embedding-e5-base/training/scripts/sample_original.py
-
curl -L -o sample_original.py https://huggingface.co/beno-rohman/product-embedding-e5-base/resolve/main/training/scripts/sample_original.py
1.94 kB
| """Randomly sample original corpus rows, without using the cleaned subset.""" | |
| import gzip | |
| import json | |
| from pathlib import Path | |
| import random | |
| def main(): | |
| root = Path(__file__).resolve().parents[1] | |
| source = root / "offers_corpus_all_v2_non_norm.json.gz" | |
| manifest = json.loads((root / "artifacts/prepared/manifest.json").read_text()) | |
| row_count = manifest["rows_scanned"] | |
| # Random order provides an unbiased order of candidate rows. Extra candidates | |
| # allow skipping records without a usable title while keeping 50 products. | |
| indices = random.SystemRandom().sample(range(row_count), 100) | |
| wanted = set(indices) | |
| found = {} | |
| observed = 0 | |
| with gzip.open(source, "rb") as handle: | |
| for index, line in enumerate(handle): | |
| observed = index + 1 | |
| if index in wanted: | |
| record = json.loads(line) | |
| title = record.get("title") | |
| if isinstance(title, str) and title.strip(): | |
| found[index] = {"source_row": index + 1, "record": record} | |
| if observed != row_count: | |
| raise ValueError("Original row count differs from the manifest") | |
| samples = [found[index] for index in indices if index in found][:50] | |
| if len(samples) != 50: | |
| raise ValueError("Insufficient titled rows in the random candidates; retry") | |
| output = root / "artifacts" | |
| # Preserve raw source records as provenance; only collapse whitespace in the | |
| # text export so each title fits on one line in the web interface. | |
| (output / "random-products-50.json").write_text(json.dumps(samples, ensure_ascii=False, indent=2), encoding="utf-8") | |
| titles = [" ".join(item["record"]["title"].split()) for item in samples] | |
| (output / "random-products-50.txt").write_text("\n".join(titles) + "\n", encoding="utf-8") | |
| print(f"Sampled {len(samples)} titles from {observed:,} original rows.") | |
| if __name__ == "__main__": | |
| main() | |