Text Ranking
sentence-transformers
ONNX
Safetensors
Transformers.js
modernbert
text-classification
reranker
cross-encoder
rerank
rag
retrieval
chinese
japanese
korean
langchain
llamaindex
haystack
text-embeddings-inference
Instructions to use CheezOne/reranker-cjk-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use CheezOne/reranker-cjk-small with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("CheezOne/reranker-cjk-small") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Transformers.js
How to use CheezOne/reranker-cjk-small with Transformers.js:
// npm i @huggingface/transformers import { AutoTokenizer, AutoModelForSequenceClassification } from '@huggingface/transformers'; const tokenizer = await AutoTokenizer.from_pretrained('CheezOne/reranker-cjk-small'); const model = await AutoModelForSequenceClassification.from_pretrained('CheezOne/reranker-cjk-small'); const query = 'Which planet is known as the Red Planet?'; const documents = [ 'Mars, known for its reddish appearance, is often referred to as the Red Planet.', 'Venus is often called the twin of Earth because of its similar size and proximity.', ]; const inputs = tokenizer(new Array(documents.length).fill(query), { text_pair: documents, padding: true, truncation: true }); const { logits } = await model(inputs); console.log(logits.sigmoid().tolist()); // one relevance score per document - Notebooks
- Google Colab
- Kaggle
File size: 3,275 Bytes
e374d55 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | """Publish a trained model directory to the Hugging Face Hub (model repo + training scripts).
Usage: HF_TOKEN=... python publish.py <model_dir> <repo_id> [--private]
Uploads: weights, tokenizer, config, onnx/, README.md, eval JSONs, and scripts/ (for reproducibility).
Never uploads checkpoints, data, or anything containing tokens.
"""
import argparse, os, re, shutil, tempfile
from huggingface_hub import HfApi
SCRIPTS = ["common.py", "prep_openpii.py", "gen_zh_realistic.py", "train.py", "export_onnx.py",
"quant_sweep.py", "bench_redaction.py", "error_analysis.py", "make_card.py", "publish.py"]
def main():
ap = argparse.ArgumentParser()
ap.add_argument("model_dir"); ap.add_argument("repo_id"); ap.add_argument("--private", action="store_true")
ap.add_argument("--extra", nargs="*", default=[], help="extra files to put under eval/")
ap.add_argument("--scripts", nargs="*", default=None, help="scripts/ files to ship (default: PII pipeline)")
a = ap.parse_args()
api = HfApi(token=os.environ["HF_TOKEN"])
api.create_repo(a.repo_id, repo_type="model", private=a.private, exist_ok=True)
here = os.path.dirname(os.path.abspath(__file__))
with tempfile.TemporaryDirectory() as tmp:
for f in os.listdir(a.model_dir):
src = os.path.join(a.model_dir, f)
if f in ("ckpt", "train_log.jsonl.bak") or f.startswith("."):
continue
if os.path.isdir(src):
if f == "onnx":
os.makedirs(os.path.join(tmp, "onnx"))
for o in ("model.onnx", "model_quantized.onnx"):
if os.path.exists(os.path.join(src, o)):
shutil.copy(os.path.join(src, o), os.path.join(tmp, "onnx", o))
continue
dst = os.path.join(tmp, "eval", f) if f.endswith(".json") and f.startswith(("eval", "onnx_report")) else os.path.join(tmp, f)
os.makedirs(os.path.dirname(dst), exist_ok=True); shutil.copy(src, dst)
os.makedirs(os.path.join(tmp, "scripts"), exist_ok=True)
for s in (a.scripts if a.scripts is not None else SCRIPTS):
if os.path.exists(os.path.join(here, s)):
shutil.copy(os.path.join(here, s), os.path.join(tmp, "scripts", s))
for e in a.extra:
os.makedirs(os.path.join(tmp, "eval"), exist_ok=True); shutil.copy(e, os.path.join(tmp, "eval", os.path.basename(e)))
secrets = [os.environ[k].encode() for k in ("HF_TOKEN", "CNB_TOKEN") if os.environ.get(k)]
for root, _, files in os.walk(tmp): # safety: refuse to upload anything that looks like a token
for f in files:
p = os.path.join(root, f)
if os.path.getsize(p) < 5_000_000:
txt = open(p, "rb").read()
assert not any(x in txt for x in secrets) and not re.search(rb"hf_[A-Za-z0-9]{30,}", txt), f"token-like string in {p}"
print("uploading:", sorted(os.path.relpath(os.path.join(r, f), tmp) for r, _, fs in os.walk(tmp) for f in fs))
api.upload_folder(folder_path=tmp, repo_id=a.repo_id, repo_type="model", commit_message="Release")
print("https://huggingface.co/" + a.repo_id)
if __name__ == "__main__":
main()
|