Views
No views yet
| Metric | Value |
|---|---|
| Pearson Correlation | 0.8650 |
| R-squared | 0.7490 |
| Mean Absolute Error | 0.1330 |
| RMSE | 0.165 |
1from transformers import AutoTokenizer
2import torch
3import torch.nn as nn
4from transformers import AutoModel
5
6class BERTCoverageRegressor(nn.Module):
7 def __init__(self, model_name='bert-base-uncased', dropout_rate=0.3):
8 super(BERTCoverageRegressor, self).__init__()
9 self.bert = AutoModel.from_pretrained(model_name)
10 self.dropout = nn.Dropout(dropout_rate)
11 self.regressor = nn.Linear(self.bert.config.hidden_size, 1)
12
13 def forward(self, input_ids, attention_mask):
14 outputs = self.bert(input_ids=input_ids, attention_mask=attention_mask)
15 pooled_output = outputs.pooler_output
16 output = self.dropout(pooled_output)
17 return self.regressor(output)
18
19# Load model and tokenizer
20tokenizer = AutoTokenizer.from_pretrained('KingTechnician/bert-osmosis-coverage')
21model = BERTCoverageRegressor()
22
23# Load the fine-tuned weights
24model_path = "pytorch_model.bin" # Download from repo
25model.load_state_dict(torch.load(model_path, map_location='cpu'))
26model.eval()
27
28# Make prediction
29def predict_coverage(objective, conversation, max_length=512):
30 encoding = tokenizer(
31 objective,
32 conversation,
33 truncation=True,
34 padding='max_length',
35 max_length=max_length,
36 return_tensors='pt'
37 )
38
39 with torch.no_grad():
40 output = model(encoding['input_ids'], encoding['attention_mask'])
41 score = torch.clamp(output.squeeze(), 0.0, 1.0).item()
42
43 return score
44
45# Example usage
46objective = "Understand the process of photosynthesis"
47conversation = "Student explains light reactions and Calvin cycle with examples..."
48coverage_score = predict_coverage(objective, conversation)
49print(f"Coverage Score: {coverage_score:.3f}")[CLS] learning_objective [SEP] student_conversation [SEP]1@misc{bert-coverage-assessment,
2 title={Domain-Agnostic Coverage Assessment Through BERT Fine-tuning},
3 author={Your Name},
4 year={2025},
5 url={https://huggingface.co/KingTechnician/bert-osmosis-coverage}
6}