distilbert sentiment encrypted

nesaorg

Introduction

The DistilBERT Sentiment Encrypted model is an encrypted version of a sentiment analysis model based on DistilBERT, designed to provide privacy through Equivariant Encryption. This approach allows inference on encrypted data without exposing plaintext to the computing environment.

Architecture

The model is built on top of the DistilBERT architecture, specifically the distilbert-base-uncased-finetuned-sst-2-english version. It employs Equivariant Encryption to keep input and output data encrypted during processing, ensuring privacy.

Training

The community edition uses an approximation of a high-fidelity encryption schema available for enterprise applications. The encrypted model is designed to replicate the original model's results with approximately 92% accuracy, with slight variations in confidence scores.

Guide: Running Locally

To run the model locally, follow these steps:

  1. Install required libraries:
    pip install torch transformers
    
  2. Load the model and tokenizer:
    import torch
    from transformers import AutoModelForSequenceClassification, AutoTokenizer
    
    model_name = "nesaorg/distilbert-sentiment-encrypted-community-v1"
    model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=2)
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    
  3. Run inference:
    inputs = tokenizer("Hello, I love you", return_tensors="pt")
    
    with torch.no_grad():
        logits = model(**inputs).logits
    
    predicted_class_id = logits.argmax().item()
    label = model.config.id2label[predicted_class_id]
    score = torch.max(torch.nn.Softmax()(logits)).item()
    print(f"The sentiment was classified as {label} with a confidence score of {score}")
    

For enhanced performance, consider using cloud GPUs such as those available on AWS, Google Cloud, or Azure, which can handle the model's computational demands efficiently.

License

The model is released under the Apache 2.0 license, allowing for both personal and commercial use with proper attribution.

More Related APIs in Text Classification