fbougares/tsac
Updated • 148 • 2
How to use tunis-ai/TunBERT with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="tunis-ai/TunBERT", trust_remote_code=True) # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("tunis-ai/TunBERT", trust_remote_code=True)
model = AutoModelForSequenceClassification.from_pretrained("tunis-ai/TunBERT", trust_remote_code=True)This is a converted version of Instadeep's TunBERT from nemo to safetensors.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("tunis-ai/TunBERT")
model = AutoModelForSequenceClassification.from_pretrained("tunis-ai/TunBERT",trust_remote_code=True)
text = "[insert text here]"
inputs = tokenizer(text,return_tensors='pt')
output = model.process(**inputs) # -> List["positive" or "negative"]
or you can use the normal forward method (currently compatible with the Trainer class)
text = "[insert text here]"
inputs = tokenizer(text,return_tensors='pt')
output = model(**inputs)
or you can use the pipeline :
⚠️currently broken try an older version of transformers until i raise this, in the mean time use the model.process method mentioned above
from transformers import pipeline
pipe = pipeline(model="tunis-ai/TunBERT",tokenizer = "tunis-ai/TunBERT",trust_remote_code=True)
pipe("text")