cnmoro/QuestionClassification
Viewer โข Updated โข 129k โข 28 โข 1
Run cnmoro/bert-tiny-question-classifier on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Use HF Jobs to fine-tune https://huggingface.co/cnmoro/bert-tiny-question-classifier. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Use HF Jobs to run batch inference with https://huggingface.co/cnmoro/bert-tiny-question-classifier on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
How to use cnmoro/bert-tiny-question-classifier with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="cnmoro/bert-tiny-question-classifier") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("cnmoro/bert-tiny-question-classifier")
model = AutoModelForSequenceClassification.from_pretrained("cnmoro/bert-tiny-question-classifier", device_map="auto")(This model has a v2, use it instead: https://huggingface.co/cnmoro/granite-question-classifier)
A finetuned version of prajjwal1/bert-tiny.
The goal is to classify questions into "Directed" or "Generic".
If a question is not directed, we would change the actions we perform on a RAG pipeline (if it is generic, semantic search wouldn't be useful directly; e.g. asking for a summary).
(Class 0 is Generic; Class 1 is Directed)
The accuracy on the training dataset is around 87.5%
from transformers import BertForSequenceClassification, BertTokenizerFast
import torch
# Load the model and tokenizer
model = BertForSequenceClassification.from_pretrained("cnmoro/bert-tiny-question-classifier")
tokenizer = BertTokenizerFast.from_pretrained("cnmoro/bert-tiny-question-classifier")
def is_question_generic(question):
# Tokenize the sentence and convert to PyTorch tensors
inputs = tokenizer(
question.lower(),
truncation=True,
padding=True,
return_tensors="pt",
max_length=512
)
# Get the model's predictions
with torch.no_grad():
outputs = model(**inputs)
# Extract the prediction
predictions = outputs.logits
predicted_class = torch.argmax(predictions).item()
return int(predicted_class) == 0