Skip to main content

gRPC inference service for multilingual BigARTM topic embeddings.

Project description

redup.python.topicmodel

Docker test Python test

gRPC inference service for a multilingual BigARTM topic model: document embeddings and topic explanations.

Contract: redup.topicmodel.v1 (GetDocumentsEmbedding, GetTopicExplanation). PyPI package: redup-topicmodel.

Model

Weights and tokenizers are published on Hugging Face:

redup-ai/topicmodel-multilingual

Expected artifact layout:

<data>/
  artm/parameters.bin
  artm/p_wt.bin
  tokenizers.json.gz
  config.json

Download locally:

pip install huggingface_hub
python -c "from huggingface_hub import snapshot_download; print(snapshot_download('redup-ai/topicmodel-multilingual'))"

Configuration

config/config.yaml:

service:
  port: "[::]:9878"

TopicModel:
  artifact_root: /data          # HF artifact root (Docker default mount)

Override without editing the file via servicekit env substitution (section___key):

export TopicModel___artifact_root=/path/to/topicmodel-multilingual

Instead of artifact_root, you can set paths explicitly: model_path (artm/ directory) and bpe_path (tokenizers.json.gz or a tokenizers directory) — also overridable as TopicModel___model_path / TopicModel___bpe_path.

Run with Docker

Pull the published image and mount the downloaded artifacts at /data (as in the config):

docker run --rm -p 9878:9878 \
  -v /path/to/topicmodel-multilingual:/data:ro \
  redup4ai/redup.python.topicmodel:0.1.0-3.11-slim

The service listens for gRPC on port 9878.

Call it from Python:

import asyncio
from redup_proto_topicmodel.client import Client
from redup_proto_topicmodel.redup.topicmodel.v1.topicmodel_pb2 import (
    Document,
    DocumentPack,
)

async def main():
    client = Client("grpc://localhost:9878")
    pack = DocumentPack(documents=[
        Document(
            document_id="doc-en",
            tokens=["hello", "world"],
            modalities={"lang": "en"},
        ),
    ])
    response = await client.get_documents_embedding("example", pack)
    print(response["embeddings"])

asyncio.run(main())

Run locally without Docker

python -m venv .venv && source .venv/bin/activate
pip install -r src/requirements.txt
pip install -e src

export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
export TopicModel___artifact_root=/path/to/topicmodel-multilingual
PYTHONPATH=src python -m redup_topicmodel.service config/config.yaml

Tests

PYTHONPATH=src python -m pytest tests -q -m "not smoke"

Smoke test with a real model (requires TOPICMODEL_DATA or TopicModel___artifact_root):

export TOPICMODEL_DATA=/path/to/topicmodel-multilingual
PYTHONPATH=src python -m pytest tests -q --smoke

License

MIT — see LICENSE.

Parts of the inference logic are adapted from text_categorization (Copyright (c) 2020, Machine Intelligence Team), BSD 3-Clause. See NOTICE and third_party/text_categorization/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redup_topicmodel-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redup_topicmodel-0.1.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file redup_topicmodel-0.1.0.tar.gz.

File metadata

  • Download URL: redup_topicmodel-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for redup_topicmodel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8c520c602d69dc5875eec515926a39af25a103426bd6204e608855448e7c72c6
MD5 642d6791aad49a5456fa1d3509664816
BLAKE2b-256 5244f2232a6332dcd0730ec70f20d8cd1eb949469023c99025d7c2764963409f

See more details on using hashes here.

File details

Details for the file redup_topicmodel-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for redup_topicmodel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d611940025af0c33742d83d8a232f0885c52921406221915573b77ac4d5af31
MD5 1d896dfdebf76edb684479075fe186b6
BLAKE2b-256 704431236bf397606704ee659cf8a33662b155b8ca535b09a977fd018445525a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page