Downloads · 30 days
0
Aliemree/veri_seti
veri_seti is a machine learning model from Aliemree. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
import pandas as pd from datasets import Dataset
Downloads · 30 days
0
Access
Public
Updated Jul 19, 2024
Repo size
—
Likes
0
Public
Click a slice to open those files.
Other3.4 KB · 62%
From the Hugging Face model README
import pandas as pd from datasets import Dataset
data = { 'text': [ 'Bu bir örnek metindir.', 'Türkçe doğal dil işleme projesi.', 'Veri bilimi ve makine öğrenmesi.', 'Python programlama dili.' ], 'label': [0, 1, 2, 3] }
df = pd.DataFrame(data)
dataset = Dataset.from_pandas(df) import unicodedata
def remove_accents(text): nfkd_form = unicodedata.normalize('NFKD', text) return ''.join([c for c in nfkd_form if not unicodedata.combining(c)])
def preprocess_function(examples): examples['text'] = [remove_accents(text) for text in examples['text']] return examples
processed_dataset = dataset.map(preprocess_function) from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer
model_name = "dbmdz/bert-base-turkish-cased" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=4)
def tokenize_function(examples): return tokenizer(examples['text'], padding="max_length", truncation=True)
tokenized_datasets = processed_dataset.map(tokenize_function, batched=True)
training_args = TrainingArguments( output_dir="./results", evaluation_strategy="epoch", learning_rate=2e-5, per_device_train_batch_size=8, per_device_eval_batch_size=8, num_train_epochs=3, weight_decay=0.01, )
trainer = Trainer( model=model, args=training_args, train_dataset=tokenized_datasets, eval_dataset=tokenized_datasets, )
trainer.train()
eval_results = trainer.evaluate()
print(f"Değerlendirme Sonuçları: {eval_results}")