1from huggingface_hub import snapshot_download
2
3root = snapshot_download(repo_id="redup-ai/topicmodel-multilingual")
Recommended path: the inference helpers from
redup.python.topicmodel.
1pip install huggingface_hub bigartm==0.9.2
2# install redup-topicmodel from the service repository / package index you use
1import asyncio
2from types import SimpleNamespace
3
4from redup_topicmodel.topicmodel.worker import TopicModel
5
6
7def document(document_id: str, tokens: list[str], lang: str):
8 return SimpleNamespace(
9 document_id=document_id,
10 tokens=tokens,
11 modalities={"lang": lang},
12 )
13
14
15async def main(root: str):
16 model = TopicModel({
17 "artifact_root": root,
18 })
19 pack = SimpleNamespace(documents=[
20 document("doc-en", ["hello", "world"], "en"),
21 document("doc-ru", ["привет", "мир"], "ru"),
22 ])
23 result = await model.get_documents_embedding("example", pack)
24 for embedding in result["embeddings"]:
25 # length-125 topic distribution
26 print(len(embedding["values"]), sum(embedding["values"]))
27
28
29asyncio.run(main(root))
1TopicModel:
2 artifact_root: /path/from/snapshot_download
1from redup_topicmodel.topicmodel.bpe import Tokenizers
2
3tokenizers = Tokenizers.load(f"{root}/tokenizers.json.gz")
4print(tokenizers["en"].encode("hello world"))
MIT. See LICENSE.