Question Answering
Scikit-learn
Joblib
English
bert
squad
feature-extraction
logistic-regression
baseline
Eval Results (legacy)
Instructions to use Giobbva/bert-squad-qa-feature-based with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Giobbva/bert-squad-qa-feature-based with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Giobbva/bert-squad-qa-feature-based", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
bert-squad-qa-feature-based
Baseline for extractive question answering on SQuAD v1.1: the frozen, original bert-base-uncased
is used only as a feature extractor, and two scikit-learn Logistic Regression classifiers predict the
answer span on top of its features. No BERT weight is trained.
The fully fine-tuned counterpart is published separately at Giobbva/bert-squad-qa-full-finetuning.
| Model | Exact Match | F1 |
|---|---|---|
| This model (frozen BERT + Logistic Regression) | 14.35 | 24.57 |
| Full fine-tuning (bert-squad-qa-full-finetuning) | 69.04 | 79.53 |
Evaluated on the full SQuAD v1.1 validation set (10,570 questions).
Files in this repository
Two StandardScaler + LogisticRegression pipelines, stored as .joblib files:
model1_start_classifier.joblib: scores each context word as the answer startmodel1_end_classifier.joblib: scores each context word as the answer end
This repository contains no transformer weights: load bert-base-uncased from its own repository.
Features
- Input:
last_hidden_state(768-d) of the frozenbert-base-uncasedat the first sub-token of each context word - Question and context are encoded together (
question [SEP] context), max length 384, stride 128
Training
- 15,000 SQuAD v1.1 training examples; per window, the start word, the end word and 10 randomly sampled negative context words
LogisticRegression(max_iter=300)afterStandardScaler, seed 42- Span decoding: best
start + endscore withend >= startand at most 30 words
Usage
import joblib
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoModel, AutoTokenizer
start_classifier = joblib.load(hf_hub_download("Giobbva/bert-squad-qa-feature-based", "model1_start_classifier.joblib"))
end_classifier = joblib.load(hf_hub_download("Giobbva/bert-squad-qa-feature-based", "model1_end_classifier.joblib"))
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
bert = AutoModel.from_pretrained("bert-base-uncased").eval()
question, context = "Where is the Eiffel Tower?", "The Eiffel Tower is in Paris."
encoded = tokenizer(question, context, truncation="only_second", max_length=384, return_tensors="pt")
with torch.no_grad():
hidden = bert(**encoded).last_hidden_state[0].numpy()
# first sub-token of each context word
word_ids, sequence_ids = encoded.word_ids(), encoded.sequence_ids()
positions = [i for i, w in enumerate(word_ids) if sequence_ids[i] == 1 and word_ids[i - 1] != w]
start_scores = start_classifier.decision_function(hidden[positions])
end_scores = end_classifier.decision_function(hidden[positions])
s = int(start_scores.argmax())
e = s + int(end_scores[s:s + 30].argmax())
start_char = encoded.word_to_chars(word_ids[positions[s]], sequence_index=1).start
end_char = encoded.word_to_chars(word_ids[positions[e]], sequence_index=1).end
print(context[start_char:end_char])
- Downloads last month
- -
Model tree for Giobbva/bert-squad-qa-feature-based
Base model
google-bert/bert-base-uncasedDataset used to train Giobbva/bert-squad-qa-feature-based
Viewer • Updated • 98.2k • 267k • 1.12k
Evaluation results
- exact_match on SQuAD v1.1validation set self-reported14.350
- f1 on SQuAD v1.1validation set self-reported24.570