Downloads · 30 days
4
7% of all-time downloads
lyndoncarlson/text_classification_beto_tf_9_24_2024
text_classification_beto_tf_9_24_2024 is a machine learning model from lyndoncarlson. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
This model is a binary text classifier fine-tuned from BETO (a BERT-based model pre-trained on Spanish). It is designed to predict whether a given text prompt requires a search query, enabling applications such as int…
Downloads · 30 days
4
7% of all-time downloads
All-time downloads
54
Public
Repo size
440 MB
Likes
0
Public
Click a slice to open those files.
.h5440 MB · 100%
From the Hugging Face model README
This model is a binary text classifier fine-tuned from BETO (a BERT-based model pre-trained on Spanish). It is designed to predict whether a given text prompt requires a search query, enabling applications such as intelligent search systems, content recommendation, and automated query handling in Spanish-language environments.
text_classification_beto_tf_9_24_20241 = requires search, 0 = no search).input_text): Text inputs requiring classification.requires_search): Binary labels indicating whether the prompt necessitates a search (1) or not (0).(prompt, requires_search) pairs were selected where both prompt and requires_search fields are non-empty, ensuring high-quality and relevant training data.pandas to load data from a CSV file containing the necessary columns.BertTokenizer) suitable for Spanish text.truncation=True: Truncate sequences longer than the maximum length.padding=True: Pad shorter sequences to the maximum length.max_length=512: Set maximum token length to 512 tokens.dccuchile/bert-base-spanish-wwm-casedTFBertForSequenceClassification adapted for binary classification (num_labels=2).SparseCategoricalCrossentropy with from_logits=True to handle integer labels directly.5e-5 and weight decay of 0.01.SparseCategoricalAccuracy to monitor classification accuracy during training.This split ensures that the model has ample data for learning while retaining sufficient data for unbiased evaluation.
SparseCategoricalCrossentropy on both training and validation sets.Test Loss and Test Sparse Categorical Accuracy.Below is a Python example demonstrating how to use the fine-tuned BETO model for binary text classification in Spanish. Ensure you have installed the necessary libraries (transformers, tensorflow, pandas, etc.) and have the model saved in the specified output_dir.
import tensorflow as tf
from transformers import BertTokenizer, TFBertForSequenceClassification
# Load the trained model and tokenizer
model_dir = "./text_classification_beto_tf_9_24_2024"
tokenizer = BertTokenizer.from_pretrained(model_dir)
model = TFBertForSequenceClassification.from_pretrained(model_dir)
# Prepare the input
prompt = "¿Cómo puedo mejorar la eficiencia energética en mi hogar?"
# Tokenize the input
inputs = tokenizer(
prompt,
return_tensors="tf",
max_length=512,
truncation=True,
padding=True
)
# Perform prediction
outputs = model(inputs)
logits = outputs.logits
predicted_class = tf.argmax(logits, axis=1).numpy()[0]
# Interpret the result
if predicted_class == 1:
print("Requiere búsqueda: Sí")
else:
print("Requiere búsqueda: No")
Output:
Requiere búsqueda: Sí
This script loads the fine-tuned model and tokenizer, tokenizes a sample prompt, performs a prediction, and interprets the result by indicating whether the prompt requires a search query.
Bias and Fairness:
Data Privacy:
Domain Specificity:
Misclassification Risks:
Responsible Usage: