from statistics import mean import pandas as pd from datasets import load_dataset def count_word(text): return len(text.split()) if __name__ == '__main__': data = ["chemprot", "citation_intent", "hyperpartisan_news", "rct_sample", "sciie", "amcd", 'yelp_review', 'tweet_eval_irony', 'tweet_eval_hate', 'tweet_eval_emotion'] stats = {} for d in data: _data = load_dataset('asahi417/multi_domain_document_classification', d) stats[d] = { 'word/validation': mean([count_word(k['text']) for k in _data['validation']]), 'word/test': mean([count_word(k['text']) for k in _data['test']]), 'word/train': mean([count_word(k['text']) for k in _data['train']]), 'instance/validation': len(_data['validation']), 'instance/test': len(_data['test']), 'instance/train': len(_data['train']) } df = pd.DataFrame(stats).astype(int) df.to_csv('stats.csv') print(df.to_markdown())