BERTweet-large-self-labeling
49
license:mit
by
ADS509
Embedding Model
OTHER
New
49 downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
Unknown
Mobile
Laptop
Server
Quick Summary
AI model with specialized capabilities.
Code Examples
Training procedurepython
tokenizer = AutoTokenizer.from_pretrained("bert-base_uncased")
# Function to tokenize data with
def tokenize_function(batch):
return tokenizer(
batch['text'],
truncation=True,
max_length=512 # Can't be greater than model max length
)
# Tokenize Data
train_data = dataset['train'].map(tokenize_function, batched=True)
test_data = dataset['test'].map(tokenize_function, batched=True)
valid_data = dataset['valid'].map(tokenize_function, batched=True)
# Convert lists to tensors
train_data.set_format("torch", columns=['input_ids', "attention_mask", "label"])
test_data.set_format("torch", columns=['input_ids', "attention_mask", "label"])
valid_data.set_format("torch", columns=['input_ids', "attention_mask", "label"])
model = AutoModelForSequenceClassification.from_pretrained(
MODEL_ID,
num_labels=5, # adjust this based on number of labels you're training on
device_map='cuda',
dtype='auto',
label2id=label2id,
id2label=id2label
)
# Metric function for evaluation in Trainer
def compute_metrics(eval_pred):
predictions, labels = eval_pred
predictions = np.argmax(predictions, axis=1)
return {
'accuracy': accuracy_score(labels, predictions),
'f1_macro': f1_score(labels, predictions, average='macro'),
'f1_weighted': f1_score(labels, predictions, average='weighted')
}
# Data collator to handle padding dynamically per batch
data_collator = DataCollatorWithPadding(tokenizer=tokenizer)
training_args = TrainingArguments(
output_dir='./bert-comment',
num_train_epochs=2,
per_device_train_batch_size=32,
per_device_eval_batch_size=64,
learning_rate=2e-5,
weight_decay=0.01,
warmup_steps=300,
# Evaluation & saving
eval_strategy='epoch',
save_strategy='epoch',
load_best_model_at_end=True,
metric_for_best_model='f1_macro',
# Logging
logging_steps=100,
report_to='tensorboard',
# Other
seed=42,
fp16=torch.cuda.is_available(), # Mixed precision if GPU available
)
# Set up Trainer
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_data,
eval_dataset=valid_data,
processing_class=tokenizer,
data_collator=data_collator,
compute_metrics=compute_metrics
)
# Train!
trainer.train()
# Evaluate
eval_results = trainer.evaluate()
print(eval_results)Deploy This Model
Production-ready deployment in minutes
Together.ai
Instant API access to this model
Production-ready inference API. Start free, scale to millions.
Try Free APIReplicate
One-click model deployment
Run models in the cloud with simple API. No DevOps required.
Deploy NowDisclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.