Giter Club home page Giter Club logo

pref-fend's Introduction

Pref-FEND

This is the official repository of the paper:

Integrating Pattern- and Fact-based Fake News Detection via Model Preference Learning.

Qiang Sheng*, Xueyao Zhang*, Juan Cao, and Lei Zhong.

Proceedings of the 30th ACM International Conference on Information and Knowledge Management (CIKM 2021)

PDF / Poster / Code / Chinese Blog

Datasets

The experimental datasets where can be seen in dataset folder, including the Weibo Dataset, and the Twitter Dataset. Note that you can download the datasets only after an "Application to Use the Datasets for Pattern- and Fact-based Joint Fake News Detection" has been submitted.

Code

Key Requirements

python==3.6.10
torch==1.6.0
torchvision==0.7.0
torch-geometric==1.7.0
torch-sparse==0.6.9
transformers==3.2.0

Preparation

Step1: Stylistic Tokens & Entities Recognition

Notice that Step1 is not necessary, because we have supplied the recognized results in dataset json files in dataset folder.

If you would like to know about the details of the recoginition procedure, you can refer to the preprocess/tokens_recognition folder.

Step2: Tokenize

cd preprocess/tokenize

As the run.sh shows, you need to run:

python get_post_tokens.py --dataset [dataset] --pretrained_model [bert_pretrained_model]

Step3: Heterogeneous Graph Initialization

cd preprocess/graph_init

As the run.sh shows, you need to run:

python init_graph.py --dataset [dataset] --max_nodes [max_tokens_num]

Step4: Preparation of the Fact-based Models

Notice that Step3 is not necessary if you wouldn't use fact-based models as a componet for Pref-FEND.

Tokenize
cd preprocess/tokenize

As the run.sh shows, you need to run:

python get_articles_tokens.py --dataset [dataset] --pretrained_model [bert_pretrained_model]
Retrieve by BM25
cd preprocess/bm25

As the run.sh shows, you need to run:

python retrieve.py --dataset [dataset]

Step5: Preparation for some special fake news detectors

Notice that Step5 is not necessary if you wouldn't use EANN-Text or BERT-Emo as a componet for Pref-FEND.

EANN-Text
cd preprocess/EANN_Text

As the run.sh shows, you need to run:

python events_clustering.py --dataset [dataset] --events_num [clusters_num]
BERT-Emo
cd preprocess/BERT_Emo/code/preprocess

As the run.sh shows, you need to run:

python input_of_emotions.py --dataset [dataset]

Training and Inferring

cd model
mkdir ckpts

Here we list all of our configurations and running script in run_weibo.sh and run_twitter.sh. For example, if you would like to run BERT-Emo (Pattern-based) + MAC (Fact-based) with Pref-FEND on Weibo, you can run:

# BERT_Emo + MAC (Pref-FNED)
CUDA_VISIBLE_DEVICES=0 python main.py --dataset 'Weibo' \
--use_preference_map True --use_pattern_based_model True --use_fact_based_model True \
--pattern_based_model 'BERT_Emo' --fact_based_model 'MAC' \
--lr 5e-6 --batch_size 4 --epochs 50 \
--save 'ckpts/BERT_Emo+DeClarE_with_Pref-FEND'

then the results will be saved in ckpts/BERT_Emo+DeClarE_with_Pref-FEND.

Citation

@inproceedings{Pref-FEND,
  author    = {Qiang Sheng and
               Xueyao Zhang and
               Juan Cao and
               Lei Zhong},
  title     = {Integrating Pattern- and Fact-based Fake News Detection via Model
               Preference Learning},
  booktitle = {{CIKM} '21: The 30th {ACM} International Conference on Information
               and Knowledge Management, Virtual Event, Queensland, Australia, November
               1 - 5, 2021},
  pages     = {1640--1650},
  year      = {2021},
  url       = {https://doi.org/10.1145/3459637.3482440},
  doi       = {10.1145/3459637.3482440}
}

pref-fend's People

Contributors

rmsnow avatar sheng-qiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pref-fend's Issues

运行Bert-emo(单独的和融合的报错)模型时报错

Traceback (most recent call last):
File "main.py", line 158, in
graphs_pattern, graphs_others, nums_nodes)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/ZMD/Pref-FEND-main/model/PrefFEND.py", line 100, in forward
idxs, dataset, tokens_features, map_for_fact_detector=map_entity, map_for_pattern_detector=map_pattern, fcs=self.fcs)
File "/home/cv/ZMD/Pref-FEND-main/model/PrefFEND.py", line 62, in forward_PreferencedDetector
idxs, dataset, tokens_features, map_for_pattern_detector)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/ZMD/Pref-FEND-main/model/PatternBasedModels.py", line 131, in forward
out = self.forward_BERT(idxs, dataset, nodes_tokens, maps=tokened_maps)
File "/home/cv/ZMD/Pref-FEND-main/model/PatternBasedModels.py", line 144, in forward_BERT
seq_output, _ = self.bert(input_ids)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/modeling_bert.py", line 837, in forward
return_dict=return_dict,
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/modeling_bert.py", line 492, in forward
output_attentions,
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/modeling_bert.py", line 412, in forward
output_attentions=output_attentions,
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/modeling_bert.py", line 349, in forward
output_attentions,
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/modeling_bert.py", line 250, in forward
mixed_query_layer = self.query(hidden_states)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 91, in forward
return F.linear(input, self.weight, self.bias)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/functional.py", line 1676, in linear
output = input.matmul(weight.t())
RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling cublasCreate(handle)

BERT_Emo模型和其它fact-base模型组合时是否输入向量有问题

大佬你好!单独的BERT_Emo以及其他不含BERT_Emo的模型组合都可以正常运行,只有BERT_Emo和MAC或者EVIN等组合时会报错,感觉是bert输入问题
==================== Experimental Dataset: Weibo ====================

Start time: 2023-03-25 14:57:35
save path: ckpts/BERT_Emo+DeClarE

Loading model...

Traceback (most recent call last):
File "main.py", line 57, in
model = PrefFEND(args)
File "/home/cv/ZMD/Pref-FEND-main/model/PrefFEND.py", line 29, in init
'{}(args)'.format(args.pattern_based_model))
File "", line 1, in
File "/home/cv/ZMD/Pref-FEND-main/model/PatternBasedModels.py", line 52, in init
args.bert_pretrained_model, return_dict=False)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/modeling_utils.py", line 853, in from_pretrained
**kwargs,
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/configuration_utils.py", line 312, in from_pretrained
config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/configuration_utils.py", line 335, in get_config_dict
if os.path.isdir(pretrained_model_name_or_path):
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/genericpath.py", line 42, in isdir
st = os.stat(s)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

使用Twitter数据集时将bert-base-chinese替换为bert-base-cased后报错

Start training...


Start Training Epoch 0 : 2023-03-25 16:48:34
0%| | 0/2206 [00:01<?, ?it/s]
Traceback (most recent call last):
File "main.py", line 158, in
graphs_pattern, graphs_others, nums_nodes)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/ZMD/Pref-FEND-main/model/PrefFEND.py", line 100, in forward
idxs, dataset, tokens_features, map_for_fact_detector=map_entity, map_for_pattern_detector=map_pattern, fcs=self.fcs)
File "/home/cv/ZMD/Pref-FEND-main/model/PrefFEND.py", line 62, in forward_PreferencedDetector
idxs, dataset, tokens_features, map_for_pattern_detector)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/ZMD/Pref-FEND-main/model/PatternBasedModels.py", line 131, in forward
out = self.forward_BERT(idxs, dataset, nodes_tokens, maps=tokened_maps)
File "/home/cv/ZMD/Pref-FEND-main/model/PatternBasedModels.py", line 163, in forward_BERT
out = self.fc(output)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 93, in forward
return F.linear(input, self.weight, self.bias)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/torch/nn/functional.py", line 1690, in linear
ret = torch.addmm(bias, input, weight.t())
RuntimeError: mat1 dim 1 must match mat2 dim 0

似乎是bert维度的问题,请问大佬要怎么设置呢

缺少文件

您好!python input_of_emotions.py --dataset 'Weibo' 时提示

No such file or directory: '../../resources/Chinese/大连
理工大学情感词汇本体库/preprocess/words2array.pkl'

The lack of dataset

Dear Zhang Xue Yao: I am a master student in SEU, and my research derection is in line with yours.Your paper "Pref-FEND"is quite well-wirtten, and I want to reproduce the result in this article. But I can't find the dataset refered in the article .I will appreciate it if you can kindly send me the dataset(including social media posts and relevant articles, named "Weibo Dataset" and "Twitter Dataset").I assure you that the dataset is for academic use only.Thanks so much~!

其他模型都能正常运行,只有运行BERTEMO+MAC时报错

==================== Experimental Dataset: Weibo ====================

Start time: 2023-03-20 22:48:13
save path: ckpts/BERT_Emo+DeClarE_with_Pref-FEND

Loading model...

Traceback (most recent call last):
File "main.py", line 57, in
model = PrefFEND(args)
File "/home/cv/ZMD/Pref-FEND-main/model/PrefFEND.py", line 29, in init
'{}(args)'.format(args.pattern_based_model))
File "", line 1, in
File "/home/cv/ZMD/Pref-FEND-main/model/PatternBasedModels.py", line 52, in init
args.bert_pretrained_model, return_dict=False)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/modeling_utils.py", line 853, in from_pretrained
**kwargs,
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/configuration_utils.py", line 312, in from_pretrained
config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/site-packages/transformers/configuration_utils.py", line 335, in get_config_dict
if os.path.isdir(pretrained_model_name_or_path):
File "/home/cv/miniconda3/envs/Zmd/lib/python3.6/genericpath.py", line 42, in isdir
st = os.stat(s)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.