Views
No views yet
1from transformers import AutoModel
2model = AutoModel.from_pretrained("omai-research/milco-300m", trust_remote_code=True)1# Returns a sparse COO tensor of shape [N, vocab_size]
2sparse_reps = model.encode_text(["Baltimore: The Greatest City in America", "巴尔的摩:美国最伟大的城市", "Baltimore : La plus grande ville d'Amérique"])1# Returns a list of {token: weight} dicts, sorted by weight descending
2results = model.encode_text(["Baltimore : La plus grande ville d'Amérique", "巴尔的摩:美国最伟大的城市"], return_dict=True)
3print(results[0])
4# {'e_baltimore': 1.8021222352981567, 'e_maryland': 1.2527629137039185, 'e_city': 1.202409029006958, 'e_largest': 0.9440274834632874, 'e_biggest': 0.9287132620811462, 'e_america': 0.890972912311554, 'e_usa': 0.8649974465370178, 'e_urban': 0.7201237678527832, 'e_geography': 0.6369074583053589, 'e_cities': 0.5816917419433594, 'e_us': 0.42353010177612305, 'e_is': 0.35060185194015503 ..}
5print(results[1])
6# {'e_baltimore': 1.6522579193115234, 'e_city': 1.3217558860778809, 'e_greatest': 1.1192315816879272, 'e_usa': 0.9287132620811462, 'e_maryland': 0.8281423449516296, 'e_best': 0.817850649356842, 'e_biggest': 0.8074519634246826, 'e_us': 0.6793810129165649, 'e_great': 0.630689799785614, 'e_america': 0.5255602598190308 ...}source_view=True, the LexEcho head augments the pivot representation with source-language token weights. This preserves entities and terms that may not have English equivalents:1results = model.encode_text(["巴尔的摩:美国最伟大的城市"], return_dict=True, source_view=True)
2# Shape: [N, en_vocab_size + m_vocab_size]
3# Columns [0, en_vocab_size) are pivot (English) terms
4# Columns [en_vocab_size, en_vocab_size + m_vocab_size) are source (multilingual) terms
5print(results[0])
6# {'m_</s>': 2.09375, 'e_baltimore': 1.6522579193115234, 'e_city': 1.3217558860778809, 'e_greatest': 1.12432062625885, 'e_usa': 0.9225212931632996, 'e_maryland': 0.8247235417366028, 'e_best': 0.8143964409828186, 'e_biggest': 0.8039615750312805, 'm_伟大的': 0.77734375, 'm_:': 0.6875, 'm_美国': 0.68359375, 'e_us': 0.6734226942062378, 'e_great': 0.6265231370925903}encode_query and encode_document are aliases for encode_text:1q_reps = model.encode_query(queries)
2d_reps = model.encode_document(documents)
3scores = torch.sparse.mm(q_reps, d_reps.t())1id2term = model.get_vocab()
2# {0: "e_[PAD]", 1: "e_[UNK]", ..., 30522: "m_[PAD]", ...}
3# "e_" prefix = English (pivot) vocabulary
4# "m_" prefix = multilingual (source) vocabulary| Parameter | Description |
|---|---|
lsr_encoder_checkpoint | naver/splade-v3 |
multilingual_encoder_checkpoint | Alibaba-NLP/gte-multilingual-base |
1@inproceedings{nguyen2026milco,
2 title={MILCO: Learned Sparse Retrieval Across Languages via a Multilingual Connector},
3 author={Nguyen, Thong and Lei, Yibin and Ju, Jia-Huei and Yang, Eugene and Yates, Andrew},
4 booktitle={International Conference on Learning Representations},
5 year={2026}
6}