初始化项目,由ModelHub XC社区提供模型
Model: fractalego/fact-checking Source: Original Platform
This commit is contained in:
27
.gitattributes
vendored
Normal file
27
.gitattributes
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
90
README.md
Normal file
90
README.md
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
## Fact checking
|
||||||
|
|
||||||
|
This generative model - trained on FEVER - aims to predict whether a claim is consistent with the provided evidence.
|
||||||
|
|
||||||
|
|
||||||
|
### Installation and simple usage
|
||||||
|
One quick way to install it is to type
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install fact_checking
|
||||||
|
```
|
||||||
|
|
||||||
|
and then use the following code:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from transformers import (
|
||||||
|
GPT2LMHeadModel,
|
||||||
|
GPT2Tokenizer,
|
||||||
|
)
|
||||||
|
|
||||||
|
from fact_checking import FactChecker
|
||||||
|
|
||||||
|
_evidence = """
|
||||||
|
Justine Tanya Bateman (born February 19, 1966) is an American writer, producer, and actress . She is best known for her regular role as Mallory Keaton on the sitcom Family Ties (1982 -- 1989). Until recently, Bateman ran a production and consulting company, SECTION 5 . In the fall of 2012, she started studying computer science at UCLA.
|
||||||
|
"""
|
||||||
|
|
||||||
|
_claim = 'Justine Bateman is a poet.'
|
||||||
|
|
||||||
|
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
|
||||||
|
fact_checking_model = GPT2LMHeadModel.from_pretrained('fractalego/fact-checking')
|
||||||
|
fact_checker = FactChecker(fact_checking_model, tokenizer)
|
||||||
|
is_claim_true = fact_checker.validate(_evidence, _claim)
|
||||||
|
|
||||||
|
print(is_claim_true)
|
||||||
|
```
|
||||||
|
|
||||||
|
which gives the output
|
||||||
|
|
||||||
|
```bash
|
||||||
|
False
|
||||||
|
```
|
||||||
|
|
||||||
|
### Probabilistic output with replicas
|
||||||
|
The output can include a probabilistic component, obtained by iterating a number of times the output generation.
|
||||||
|
The system generates an ensemble of answers and groups them by Yes or No.
|
||||||
|
|
||||||
|
For example, one can ask
|
||||||
|
```python
|
||||||
|
from transformers import (
|
||||||
|
GPT2LMHeadModel,
|
||||||
|
GPT2Tokenizer,
|
||||||
|
)
|
||||||
|
|
||||||
|
from fact_checking import FactChecker
|
||||||
|
|
||||||
|
_evidence = """
|
||||||
|
Jane writes code for Huggingface.
|
||||||
|
"""
|
||||||
|
|
||||||
|
_claim = 'Jane is an engineer.'
|
||||||
|
|
||||||
|
|
||||||
|
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
|
||||||
|
fact_checking_model = GPT2LMHeadModel.from_pretrained('fractalego/fact-checking')
|
||||||
|
fact_checker = FactChecker(fact_checking_model, tokenizer)
|
||||||
|
is_claim_true = fact_checker.validate_with_replicas(_evidence, _claim)
|
||||||
|
|
||||||
|
print(is_claim_true)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
with output
|
||||||
|
```bash
|
||||||
|
{'Y': 0.95, 'N': 0.05}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Score on FEVER
|
||||||
|
|
||||||
|
The predictions are evaluated on a subset of the FEVER dev dataset,
|
||||||
|
restricted to the SUPPORTING and REFUTING options:
|
||||||
|
|
||||||
|
| precision | recall | F1|
|
||||||
|
| --- | --- | --- |
|
||||||
|
|0.94|0.98|0.96|
|
||||||
|
|
||||||
|
These results should be taken with many grains of salt. This is still a work in progress,
|
||||||
|
and there might be leakage coming from the underlining GPT2 model unnaturally raising the scores.
|
||||||
|
|
||||||
|
|
||||||
38
config.json
Normal file
38
config.json
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"_name_or_path": "gpt2",
|
||||||
|
"activation_function": "gelu_new",
|
||||||
|
"architectures": [
|
||||||
|
"GPT2LMHeadModel"
|
||||||
|
],
|
||||||
|
"attn_pdrop": 0.1,
|
||||||
|
"bos_token_id": 50256,
|
||||||
|
"embd_pdrop": 0.1,
|
||||||
|
"eos_token_id": 50256,
|
||||||
|
"gradient_checkpointing": false,
|
||||||
|
"initializer_range": 0.02,
|
||||||
|
"layer_norm_epsilon": 1e-05,
|
||||||
|
"model_type": "gpt2",
|
||||||
|
"n_ctx": 1024,
|
||||||
|
"n_embd": 768,
|
||||||
|
"n_head": 12,
|
||||||
|
"n_inner": null,
|
||||||
|
"n_layer": 12,
|
||||||
|
"n_positions": 1024,
|
||||||
|
"resid_pdrop": 0.1,
|
||||||
|
"scale_attn_weights": true,
|
||||||
|
"summary_activation": null,
|
||||||
|
"summary_first_dropout": 0.1,
|
||||||
|
"summary_proj_to_labels": true,
|
||||||
|
"summary_type": "cls_index",
|
||||||
|
"summary_use_proj": true,
|
||||||
|
"task_specific_params": {
|
||||||
|
"text-generation": {
|
||||||
|
"do_sample": true,
|
||||||
|
"max_length": 50
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"torch_dtype": "float32",
|
||||||
|
"transformers_version": "4.9.1",
|
||||||
|
"use_cache": true,
|
||||||
|
"vocab_size": 50257
|
||||||
|
}
|
||||||
50001
merges.txt
Normal file
50001
merges.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
pytorch_model.bin
Normal file
3
pytorch_model.bin
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:9b1f5f8762c5809d37d491f311c2d89140ad96cc19bdf62766eb73e05b48af0a
|
||||||
|
size 510401385
|
||||||
1
special_tokens_map.json
Normal file
1
special_tokens_map.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}}
|
||||||
1
tokenizer_config.json
Normal file
1
tokenizer_config.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"errors": "replace", "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "add_prefix_space": false, "model_max_length": 1024, "special_tokens_map_file": null, "tokenizer_file": "/home/alce/.cache/huggingface/transformers/16a2f78023c8dc511294f0c97b5e10fde3ef9889ad6d11ffaa2a00714e73926e.cf2d0ecb83b6df91b3dbb53f1d1e4c311578bfd3aa0e04934215a49bf9898df0", "name_or_path": "gpt2", "tokenizer_class": "GPT2Tokenizer"}
|
||||||
1
vocab.json
Normal file
1
vocab.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user