Views
No views yet
bert-base-uncased model that has been fine-tuned for the multiple-choice question-answering task using the SWAG (Situations with Adversarial Generations) dataset. The fine-tuning was performed using a parameter-efficient technique called LoRA (Low-Rank Adaptation), which significantly reduces the number of trainable parameters while achieving strong performance.google-bert/bert-base-uncasedhttps://huggingface.co/[Your Hugging Face Username]/bert-base-swag-lora1from transformers import AutoModelForMultipleChoice, AutoTokenizer
2from peft import PeftModel
3import torch
4
5# Define your repository name
6repo_name = "[Your Hugging Face Username]/bert-base-swag-lora"
7base_model_name = "google-bert/bert-base-uncased"
8
9# Load the fine-tuned model from the Hub
10tokenizer = AutoTokenizer.from_pretrained(repo_name)
11base_model = AutoModelForMultipleChoice.from_pretrained(base_model_name)
12model = PeftModel.from_pretrained(base_model, repo_name)
13model.eval()
14
15# Example from SWAG
16context = "A man is skiing down a mountain."
17choices = [
18 "he falls down and gets back up.",
19 "he makes a snowball and throws it.",
20 "he takes a picture of the scenery.",
21 "he stops to drink some water."
22]
23
24# Prepare the input
25prompt = [context] * 4
26next_sentences = [f"{choices[i]}" for i in range(4)]
27inputs = tokenizer(prompt, next_sentences, return_tensors="pt", padding=True)
28
29# Reshape for the model
30inputs = {k: v.unsqueeze(0) for k, v in inputs.items()}
31
32# Get prediction
33with torch.no_grad():
34 outputs = model(**inputs)
35 predicted_index = torch.argmax(outputs.logits).item()
36
37print(f"The most likely ending is: '{choices[predicted_index]}'")
38# Expected output: 'he falls down and gets back up.'