Укажи на отличия между скриптами:
Первый:
!pip install datasets
!pip install transformers
!pip install evaluate


from typing import List, Tuple
from datasets import load_dataset, Dataset
import evaluate
import numpy as np
from sklearn.metrics import classification_report
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import DataCollatorWithPadding
from transformers import TrainingArguments, Trainer
from transformers import pipeline


MODEL_NAME = 'DeepPavlov/rubert-base-cased'
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)


DATASET_NAME = 'Davlan/sib200'
DATASET_LANGUAGE = 'rus_Cyrl'
train_set = load_dataset(DATASET_NAME, DATASET_LANGUAGE, split='train')
validation_set = load_dataset(DATASET_NAME, DATASET_LANGUAGE, split='validation')
test_set = load_dataset(DATASET_NAME, DATASET_LANGUAGE, split='test')

print(train_set)


MINIBATCH_SIZE = 64
tokenized_train_set = train_set.map(
    lambda it: tokenizer(it['text'], truncation=True),
    batched=True, batch_size=MINIBATCH_SIZE
)
tokenized_validation_set = validation_set.map(
    lambda it: tokenizer(it['text'], truncation=True),
    batched=True, batch_size=MINIBATCH_SIZE
)

print(tokenized_train_set)


cls_metric = evaluate.load('f1')

def compute_metrics(eval_pred):
    predictions, labels = eval_pred
    predictions = np.argmax(predictions, axis=1)
    return cls_metric.compute(predictions=predictions, references=labels, average='macro')


data_collator = DataCollatorWithPadding(tokenizer=tokenizer)

list_of_categories = sorted(list(
    set(train_set['category']) | set(validation_set['category']) | set(test_set['category'])
))
indices_of_categories = list(range(len(list_of_categories)))
n_categories = len(list_of_categories)
print(f'Categories for classification are: {list_of_categories}')
id2label = dict(zip(indices_of_categories, list_of_categories))
label2id = dict(zip(list_of_categories, indices_of_categories))

labeled_train_set = tokenized_train_set.add_column(
    'label',
    [label2id[val] for val in tokenized_train_set['category']]
)
labeled_validation_set = tokenized_validation_set.add_column(
    'label',
    [label2id[val] for val in tokenized_validation_set['category']]
)


print(labeled_train_set)


classifier = AutoModelForSequenceClassification.from_pretrained(
    MODEL_NAME,
    num_labels=n_categories, id2label=id2label, label2id=label2id
).cuda()
for param in classifier.parameters(): param.data = param.data.contiguous()



training_args = TrainingArguments(
    output_dir='rubert_sib200',
    learning_rate=2e-5,
    per_device_train_batch_size=MINIBATCH_SIZE,
    per_device_eval_batch_size=MINIBATCH_SIZE,
    num_train_epochs=20,
    weight_decay=1e-3,
    eval_strategy='epoch',
    save_strategy='epoch',
    load_best_model_at_end=True
)

trainer = Trainer(
    model=classifier,
    args=training_args,
    train_dataset=labeled_train_set,
    eval_dataset=labeled_validation_set,
    tokenizer=tokenizer,
    data_collator=data_collator,
    compute_metrics=compute_metrics,
)

trainer.train()


classifiсation_pipeline = pipeline('text-classification', model=classifier, tokenizer=tokenizer, device=0)

y_pred = list(map(lambda x: x['label'], classifiсation_pipeline(validation_set['text'])))
y_true = validation_set['category']
print(classification_report(y_true=y_true, y_pred=y_pred))

y_pred = list(map(lambda x: x['label'], classifiсation_pipeline(test_set['text'])))
y_true = test_set['category']
print(classification_report(y_true=y_true, y_pred=y_pred))
Второй:
from typing import List, Tuple
from datasets import load_dataset, Dataset
import evaluate
import numpy as np
from sklearn.metrics import classification_report
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import DataCollatorWithPadding
from transformers import TrainingArguments, Trainer
from transformers import pipeline

# Define model name for classification
MODEL_NAME = 'cointegrated/rubert-tiny' # smaller, faster version of RuBERT
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) # for inputs preprocessing 

DATASET_NAME = 'Davlan/sib200' 
DATASET_LANGUAGE = 'rus_Cyrl'
train_set = load_dataset(DATASET_NAME, DATASET_LANGUAGE, split='train')
validation_set = load_dataset(DATASET_NAME, DATASET_LANGUAGE, split='validation')
test_set = load_dataset(DATASET_NAME, DATASET_LANGUAGE, split='test')

# Define minibatch size and tokenize datasets
MINIBATCH_SIZE = 64 # batching helps in efficiently processing multiple examples at once allowing parallel computation
# converting text to tokens
tokenized_train_set = train_set.map(
    lambda it: tokenizer(it['text'], truncation=True),
    batched=True, batch_size=MINIBATCH_SIZE
)
tokenized_validation_set = validation_set.map(
    lambda it: tokenizer(it['text'], truncation=True),
    batched=True, batch_size=MINIBATCH_SIZE
)

cls_metric = evaluate.load('f1') # for evaluating the performance of the classification model

# Define a function to compute performance metrics during evaluation
# It transforms logits to predicted labels and calculates the F1 score, which is 
# the harmonic mean of precision and recall providing a balance of both
def compute_metrics(eval_pred):
    predictions, labels = eval_pred
    predictions = np.argmax(predictions, axis=1)
    return cls_metric.compute(predictions=predictions, references=labels, average='macro')

# Instantiate a data collator that dynamically pads batch elements to the same length
data_collator = DataCollatorWithPadding(tokenizer=tokenizer)

# Gather and sort the possible categories in the dataset for classification labels
# This step is essential to map string labels to numerical IDs needed by the model
list_of_categories = sorted(list(
    set(train_set['category']) | set(validation_set['category']) | set(test_set['category'])
))
indices_of_categories = list(range(len(list_of_categories)))
n_categories = len(list_of_categories)
print(f'Categories for classification are: {list_of_categories}')  # Log the categories
# Create mappings between labels and numerical IDs used by the classifier
id2label = dict(zip(indices_of_categories, list_of_categories))
label2id = dict(zip(list_of_categories, indices_of_categories))

# Add a numeric label column to train and validation datasets using the created mappings
# These labels will be used during the training process
labeled_train_set = tokenized_train_set.add_column(
    'label',
    [label2id[val] for val in tokenized_train_set['category']]
)
labeled_validation_set = tokenized_validation_set.add_column(
    'label',
    [label2id[val] for val in tokenized_validation_set['category']]
)

# Load the pre-trained model for sequence classification and configure it for our specific number of categories
classifier = AutoModelForSequenceClassification.from_pretrained(
    MODEL_NAME,
    num_labels=n_categories, id2label=id2label, label2id=label2id
)
for param in classifier.parameters(): param.data = param.data.contiguous()

training_args = TrainingArguments(
    output_dir='rubert_sib200',  # Directory to save the model's output
    learning_rate=3e-5,  # Learning rate controls how much to adjust the model's weights during training; experimentation can identify optimal values
    per_device_train_batch_size=32,  # Number of training examples processed together in a single update; larger batches may use more effective parallelism
    per_device_eval_batch_size=32,  # Similar batch size for evaluation
    num_train_epochs=25,  # Number of times the model will be trained on the entire training set; more epochs can improve or overfit the model
    weight_decay=0.01,  # Regularization parameter to prevent overfitting by penalizing large weights
    eval_strategy='epoch',  # Evaluate the model performance at the end of each epoch
    save_strategy='epoch',  # Save the model at the end of each epoch for potential restoration
    load_best_model_at_end=True  # Restore the best performing model at the end of training for final testing
)

trainer = Trainer(
    model=classifier,
    args=training_args,
    train_dataset=labeled_train_set,
    eval_dataset=labeled_validation_set,
    tokenizer=tokenizer,
    data_collator=data_collator,
    compute_metrics=compute_metrics,
)

trainer.train()

classifiсation_pipeline = pipeline('text-classification', model=classifier, tokenizer=tokenizer, device=-1)

# Predict the categories for the validation set texts and generate a classification report
# The report includes precision, recall, F1-score, and support for each class
y_pred = list(map(lambda x: x['label'], classifiсation_pipeline(validation_set['text'])))
y_true = validation_set['category']
print(classification_report(y_true=y_true, y_pred=y_pred))

# Similarly, predict the categories for the test set texts and generate a classification report
y_pred = list(map(lambda x: x['label'], classifiсation_pipeline(test_set['text'])))
y_true = test_set['category']
print(classification_report(y_true=y_true, y_pred=y_pred))