Skip to main content

Python implementation for text classification inference with CamemBERT fine-tuned models

Project description

infer-camembert

Python implementation for text classification inference with CamemBERT fine-tuned models

PyPI GitHub tag (latest by date) GitHub last commit GitHub issues GitHub

This is a simple Python implementation for the inference step of a fine-tuned text classification model based on Transformer's camembert-base model and saved in HuggingFace™.

Usage

$ pip install infer-camembert

For a private model, you must provide your HuggingFace token, either as an environment variable or under the ~/.huggingface folder:

$ HUGGINGFACE_TOKEN=<value> python3 -m infercamembert --input=example.jsonl --dictionary=labels.json --model="your-public-or-private-model-on-huggingface" --threshold=0.1 > results.jsonl

Inputs must be in the form of a dict with the keys being your unique IDs and the values the text on which to perform inference, eg.

{
  "id1": "Very nice time spent in a gorgeous site.",
  "id2": "Still a problem after three years: intolerable!!!!!!",
}

The same thing goes for the dictionary of labels where the keys should be your short custom labels and the value their corresponding long labels, eg.

{
  "label0": "undefined",
  "label1": "pleasure",
  "label2": "fun",
  "label3": "anger",
}

The results are presented as an array of predictions per input line, eg.

[
  {
    "id": "id1",
    "text": "Very nice time spent in a gorgeous site.", 
    "labels": [
      "pleasure",
      "fun"
    ]
  },
  {
    "id": "id2",
    "text": "Still a problem after three years: intolerable!!!!!!",
    "labels": [
      "anger"
    ]
  }
]

Used as a Python library:

from infercamembert import infer, Labels, ModelParameters

inputs = {
    "id1": "Very nice time spent in a gorgeous site.",
    "id2": "Still a problem after three years: intolerable!!!!!!",
}
labels = Labels(
    {
        "label0": "undefined",
        "label1": "pleasure",
        "label2": "fun",
        "label3": "anger",
    }
)
params = ModelParameters("your-public-or-private-model-on-huggingface", 0.1)
outputs = infer(inputs, labels, params)

License

This module is distributed under a MIT license.
See the LICENSE file.


© 2024-2026 Cyril Dever. All rights reserved.

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

infer_camembert-0.2.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

infer_camembert-0.2.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file infer_camembert-0.2.1.tar.gz.

File metadata

  • Download URL: infer_camembert-0.2.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.2

File hashes

Hashes for infer_camembert-0.2.1.tar.gz
Algorithm Hash digest
SHA256 cfc16a51396e7854e23d1b5b4c5c77bd723f8c48904f975d796a44ef5e155f15
MD5 b62c1b24eba45005ffec78cd7bb40b2e
BLAKE2b-256 164f1caf169acfbd95b93d65cd239b00e73d29c786a8b8360721f4e8998d92a9

See more details on using hashes here.

File details

Details for the file infer_camembert-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for infer_camembert-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 edb0c97319b74ff3828d70d12e17dc7c429becf2cd29d53b898c46d9bd01e508
MD5 1e6751aacd49ae20d54679bc585032bd
BLAKE2b-256 a085cb93b1907723bf72c6e50f2c0c0fd355a303fdad47deb3b2e9f3d365126b

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