Package: faknow
FaKnowFaKnow(FakeKnow), a unifiedFake News Detectionalgorithms library based on PyTorch, is designed for
reproducing and developing fake news detection algorithms. It includes22 models(see atIntegrated Models), covering2 categories:content basedsocial contextFeaturesUnified Framework: provide a unified interface to cover a series of algorithm development processes, including data processing, model developing, training and evaluationGeneric Data Structure: use json as the file format read into the framework to fit the format of the data crawled down, allowing the user to customize the processing of different fieldsDiverse Models: contains a number of representative fake news detection algorithms published in conferences or journals during recent years, including a variety of content-based and social context-based modelsConvenient Usability: pytorch based style makes it easy to use with rich auxiliary functions like loss visualization, logging, parameter savingGreat Scalability: users just focus on the exposed API and inherit built-in classes to reuse most of the functionality and only need to write a little code to meet new requirementsInstallationFaKnow is available forPython 3.8and higher.Make surePyTorch(including torch and torchvision) andPyG(including torch_geometric and optional dependencies) are already installed.from pippipinstallfaknowfrom sourcegitclonehttps://github.com/NPURG/FaKnow.git&&cdFaKnow
pipinstall-e.--verboseUsage ExamplesQuick StartWe provide several methods torun integrated modelsquickly with passing only few arguments. For hyper parameters
like learning rate, values from the open source code of the paper are taken as default. You can also pass your own
defined hyper parameters to these methods.runYou can userunandrun_from_yamlmethods to run integrated models. The former receives the parameters asdictkeyword arguments and the latter reads them from theyamlconfiguration file.run from kargsfromfaknow.runimportrunmodel='mdfend'# lowercase short name of modelskargs={'train_path':'train.json','test_path':'test.json'}# dict argumentsrun(model,**kargs)the json file formdfendshould be like:[{"text":"this is a sentence.","domain":9,"label":1},{"text":"this is a sentence.","domain":1,"label":0}]run from yaml# demo.pyfromfaknow.runimportrun_from_yamlmodel='mdfend'# lowercase short name of modelsconfig_path='mdfend.yaml'# config file pathrun_from_yaml(model,config_path)your yaml config file should be like:# mdfend.yamltrain_path:train.json# the path of training set filetest_path:test.json# the path of testing set filerun specific modelsYou can also run specific models usingrun_$model$andrun_$model$_from_yamlmethods by passing parameter,
where$model$should be the lowercase name of the integrated model you want to use.
The usages are the same asrunandrun_from_yaml.
Following is an example to runmdfend.fromfaknow.run.content_based.run_mdfendimportrun_mdfend,run_mdfend_from_yaml# run from kargskargs={'train_path':'train.json','test_path':'test.json'}# dict training argumentsrun_mdfend(**kargs)# or run from yamlconfig_path='mdfend.yaml'# config file pathrun_mdfend_from_yaml(config_path)Run From ScratchFollowing is an example to runmdfendfrom scratch.fromfaknow.data.dataset.textimportTextDatasetfromfaknow.data.process.text_processimportTokenizerFromPreTrainedfromfaknow.evaluate.evaluatorimportEvaluatorfromfaknow.model.content_based.mdfendimportMDFENDfromfaknow.train.trainerimportBaseTrainerimporttorchfromtorch.utils.dataimportDataLoader# tokenizer for MDFENDmax_len,bert=170,'bert-base-uncased'tokenizer=TokenizerFromPreTrained(max_len,bert)# datasetbatch_size=64train_path,test_path,validate_path='train.json','test.json','val.json'train_set=TextDataset(train_path,['text'],tokenizer)train_loader=DataLoader(train_set,batch_size,shuffle=True)validate_set=TextDataset(validate_path,['text'],tokenizer)val_loader=DataLoader(validate_set,batch_size,shuffle=False)test_set=TextDataset(test_path,['text'],tokenizer)test_loader=DataLoader(test_set,batch_size,shuffle=False)# prepare modeldomain_num=9model=MDFEND(bert,domain_num)# optimizer and lr schedulerlr,weight_decay,step_size,gamma=0.00005,5e-5,100,0.98optimizer=torch.optim.Adam(params=model.parameters(),lr=lr,weight_decay=weight_decay)scheduler=torch.optim.lr_scheduler.StepLR(optimizer,step_size,gamma)# metrics to evaluate the model performanceevaluator=Evaluator()# train and validatenum_epochs,device=50,'cpu'trainer=BaseTrainer(model,evaluator,optimizer,scheduler,device=device)trainer.fit(train_loader,num_epochs,validate_loader=val_loader)# show test resultprint(trainer.evaluate(test_loader))Integrated Modelscategorypaperjournal/conferencepublish yearsource repositoryour codeContent BasedConvolutional Neural Networks for Sentence ClassificationEMNLP2014yoonkim/CNN_sentenceTextCNNEANN: Event Adversarial Neural Networks for Multi-Modal Fake News DetectionKDD2018yaqingwang/EANN-KDD18EANNSpotFake: A Multimodal Framework for Fake News DetectionBigMM2019shiivangii/SpotFakeSpotFakeSAFE: Similarity-Aware Multi-Modal Fake News DetectionPAKDD2020Jindi0/SAFESAFEMDFEND: Multi-domain Fake News DetectionCIKM2021kennqiang/MDFEND-Weibo21MDFENDMultimodal Fusion with Co-Attention Networks for Fake News DetectionACL2021wuyang45/MCAN_codeMCANHMCAN: Hierarchical Multi-modal Contextual Attention Network for fake news DetectionSIGIR2021wangjinguang502/HMCANHMCANMFAN: Multi-modal Feature-enhanced Attention Networks for Rumor DetectionIJCAI2022drivsaf/MFANMFANGeneralizing to the Future: Mitigating Entity Bias in Fake News DetectionSIGIR2022ICTMCG/ENDEF-SIGIR2022ENDEFM3FEND: Memory-Guided Multi-View Multi-Domain Fake News DetectionTKDE2022ICTMCG/M3FENDM3FENDCAFE: Cross-modal Ambiguity Learning for Multimodal Fake News DetectionWWW2022cyxanna/CAFECAFESocial ContextSemi-Supervised Classification with Graph Convolutional NetworksICLR2017safe-graph/GNN-FakeNewsGCNInductive Representation Learning on Large GraphsNeurIPS2017safe-graph/GNN-FakeNewsGraphSAGEGraph Attention NetworksICLR2018safe-graph/GNN-FakeNewsGATFake News Detection on Social Media using Geometric Deep LearningarXiv2019safe-graph/GNN-FakeNewsGCNFNRumor detection on social media with bi-directional graph convolutional networksAAAI2020safe-graph/GNN-FakeNewsBIGCNFANG: Leveraging Social Context for Fake News Detection Using Graph RepresentationCIKM2020nguyenvanhoang7398/FANGFangGraph neural networks with continual learning for fake news detection from social mediaarXiv2020safe-graph/GNN-FakeNewsGNNCLUser Preference-aware Fake News DetectionSIGIR2021safe-graph/GNN-FakeNewsUPFDDUDEF: Mining Dual Emotion for Fake News DetectionWWW2021RMSnow/WWW2021DUDEFTowards Propagation Uncertainty: Edge-enhanced Bayesian Graph Convolutional Networks for Rumor Detection, ACL 2021ACL2021weilingwei96/EBGCNEBGCNTowards Trustworthy Rumor Detection with Interpretable Graph Structural LearningCIKM2023Anonymous4ScienceAuthor/TrustRDTrustRDCitation@misc{faknow,
  title ={{{FaKnow}}:{{A Unified Library}}for{{Fake News Detection}}},
  shorttitle ={{{FaKnow}}},
  author ={Zhu, Yiyuan and Li, Yongjun and Wang, Jialiang and Gao, Ming and Wei, Jiali},
  year ={2024},
  month = jan,
  number ={arXiv:2401.16441},
  eprint ={2401.16441},
  primaryclass ={cs},
  publisher ={{arXiv}},
  archiveprefix ={arxiv},
  keywords ={Computer Science - Artificial Intelligence,Computer Science - Computation and Language,Computer Science - Machine Learning}}LicenseFaKnow has aMIT-style license, as found in theLICENSEfile.