Views
No views yet
reranker_beto_pytorch_optimized(prompt, content) pair, the model outputs a single numerical score indicating predicted relevance.(prompt, content, rank) tuples from the database.prompt, content) were tokenized using the BETO tokenizer (cased) with:
max_length = 512doc_stride = 256 (for lengthy passages)rank field was normalized and mapped to a continuous value (relevance) for regression.dccuchile/bert-base-spanish-wwm-casedrelevance scoreAdamW with a learning rate of 3e-5sklearn.model_selection.train_test_split.test_loss../reranker_beto_pytorch_optimized, you can do:1import torch
2from transformers import BertTokenizer, BertForSequenceClassification
3
4device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5
6# Load the fine-tuned model and tokenizer
7model_dir = "./reranker_beto_pytorch_optimized"
8tokenizer = BertTokenizer.from_pretrained(model_dir)
9model = BertForSequenceClassification.from_pretrained(model_dir).to(device)
10model.eval()
11
12prompt = "¿Cómo implementar un sistema solar en una escuela primaria?"
13passage = "Este documento describe las partes del sistema solar ..."
14
15inputs = tokenizer(
16 prompt,
17 passage,
18 max_length=512,
19 truncation='only_second',
20 padding='max_length',
21 return_tensors='pt'
22)
23
24# Forward pass
25with torch.no_grad():
26 outputs = model(
27 input_ids=inputs['input_ids'].to(device),
28 attention_mask=inputs['attention_mask'].to(device)
29 )
30score = outputs.logits.squeeze().item()
31
32print(f"Predicted relevance score: {score:.4f}")