Views
No views yet
allenai/longformer-base-4096 model, designed for text classification tasks in document management, specifically for classifying Spanish-language input documents into document type categories (tipo_documento_codigo). Developed by Excribe.co, this model leverages the Longformer architecture to handle long texts (up to 4096 tokens) and is optimized for GPU environments, such as NVIDIA A100.final.parquet) containing 8,850 samples across 109 document type classes. It addresses class imbalance using SMOTE (Synthetic Minority Over-sampling Technique) applied to the training set, ensuring robust performance on minority classes. The fine-tuning process achieved an evaluation F1-score of 0.4855, accuracy of 0.6096, precision of 0.5212, and recall of 0.5006 on a validation set of 1,770 samples.texto_entrada) from documents.tipo_documento_codigo) from 109 classes.final.parquet) consists of 8,850 Spanish text samples, each labeled with a document type code (tipo_documento_codigo). The dataset exhibits significant class imbalance, with class frequencies ranging from 10 to 2,363 samples per class. The dataset was split into:allenai/longformer-base-4096, a transformer model designed for long-document processing with a sparse attention mechanism, allowing efficient handling of sequences up to 4096 tokens.Trainer API with the following configuration:./results, with TensorBoard logs in ./logs. The final model and tokenizer are saved in ./fine_tuned_longformer.pip install transformers torch pandas scikit-learn numpy1from transformers import LongformerTokenizer, LongformerForSequenceClassification
2import torch
3import numpy as np
4
5# Load the model and tokenizer
6model_path = "excribe/classifier_sgd_longformer_4099"
7tokenizer = LongformerTokenizer.from_pretrained(model_path)
8model = LongformerForSequenceClassification.from_pretrained(model_path)
9
10# Load label encoder classes
11label_encoder_classes = np.load("label_encoder_classes.npy", allow_pickle=True)
12id2label = {i: int(label) for i, label in enumerate(label_encoder_classes)}
13
14# Example text
15text = "Your Spanish document text here..."
16
17# Tokenize input
18inputs = tokenizer(
19 text,
20 add_special_tokens=True,
21 max_length=4096,
22 padding="max_length",
23 truncation=True,
24 return_tensors="pt"
25)
26
27# Move inputs to GPU if available
28device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
29model.to(device)
30inputs = {k: v.to(device) for k, v in inputs.items()}
31
32# Perform inference
33model.eval()
34with torch.no_grad():
35 outputs = model(**inputs)
36 logits = outputs.logits
37 predicted_id = torch.argmax(logits, dim=1).item()
38
39# Map prediction to label
40predicted_label = id2label[predicted_id]
41print(f"Predicted document type code: {predicted_label}")label_encoder_classes.npy) must be available to map predicted IDs to document type codes.@misc{excribe_classifier_sgd_longformer_4099,
author = {Excribe.co},
title = {Classifier SGD Longformer 4099: A Fine-Tuned Model for Spanish Document Type Classification},
year = {2025},
publisher = {Hugging Face},
url = {https://huggingface.co/excribe/classifier_sgd_longformer_4099}
}allenai/longformer-base-4096 model.transformers library and Trainer API.imbalanced-learn and scikit-learn.