BERT-Based Classification Model for Optimal Temperature Selection

This model leverages a BERT-based classification model to analyze input prompts and identify the most suitable generation temperature, enhancing text generation quality and relevance from our paper related to temperature.

Overview

The model classifies input text into six distinct abilities, providing a probability distribution for each:

  • Causal Reasoning
  • Creativity
  • In-Context Learning
  • Instruction Following
  • Machine Translation
  • Summarization

Features

  • Pre-trained Model: Uses the multilingual BERT model: Volavion/bert-base-multilingual-uncased-Temperature-CLS.
  • Tokenization: Processes text inputs into numerical formats compatible with the model.
  • Classification Output: Provides probabilities for each class, allowing precise evaluation of the prompt's capabilities.

Installation

  1. Clone the repository if necessary:

    git clone https://huggingface.co/Volavion/bert-base-multilingual-uncased-temperature-cls
    cd bert-base-multilingual-uncased-temperature-cls
    
  2. Install the required Python libraries:

    pip install transformers torch numpy
    

Usage

  1. Load the tokenizer and model:

    from transformers import AutoTokenizer, AutoModelForSequenceClassification
    
    model_name = "Volavion/bert-base-multilingual-uncased-Temperature-CLS"
    tokenizer = AutoTokenizer.from_pretrained(model_name, do_lower_case=True)
    model = AutoModelForSequenceClassification.from_pretrained(model_name)
    
  2. Tokenize your input text:

    input_text = "Your input prompt here."
    encoded_dict = tokenizer.encode_plus(
        input_text,
        add_special_tokens=True,
        max_length=512,
        pad_to_max_length=True,
        return_attention_mask=True,
        return_tensors="pt"
    )
    
  3. Perform inference:

    import torch
    import numpy as np
    
    input_ids = encoded_dict["input_ids"].to(device)
    attention_mask = encoded_dict["attention_mask"].to(device)
    
    model.eval()
    with torch.no_grad():
        outputs = model(input_ids, attention_mask=attention_mask)
    
    logits = outputs.logits.cpu().numpy()
    probabilities = np.exp(logits - np.max(logits, axis=1, keepdims=True))
    probabilities /= np.sum(probabilities, axis=1, keepdims=True)
    
  4. Map probabilities to abilities:

    ability_mapping = {0: "Causal Reasoning", 1: "Creativity", 2: "In-Context Learning",
                       3: "Instruction Following", 4: "Machine Translation", 5: "Summarization"}
    for prob, ability in zip(probabilities[0], ability_mapping.values()):
        print(f"{ability}: {prob*100:.2f}%")
    

Example Output

Ability Classification Probabilities:
Causal Reasoning: 15.30%
Creativity: 20.45%
In-Context Learning: 18.22%
Instruction Following: 12.78%
Machine Translation: 21.09%
Summarization: 12.16%

Device Compatibility

The model supports GPU acceleration for faster inference. It will automatically detect and utilize a GPU if available; otherwise, it defaults to CPU.

Contributing

Contributions are welcome! Feel free to fork the repository, create a branch, and submit a pull request.

License

This project is licensed under the MIT License.

Downloads last month
294
Safetensors
Model size
167M params
Tensor type
F32
·
Inference Providers NEW
This model is not currently available via any of the supported third-party Inference Providers, and HF Inference API was unable to determine this model's library.

Model tree for Volavion/bert-base-multilingual-uncased-temperature-cls

Finetuned
(1725)
this model