Delete usage_example.py
Browse files- usage_example.py +0 -175
usage_example.py
DELETED
|
@@ -1,175 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Usage example for the DeepScholarBench dataset.
|
| 4 |
-
|
| 5 |
-
This shows how to use the dataset builder directly, which is the recommended approach
|
| 6 |
-
for local development and testing.
|
| 7 |
-
"""
|
| 8 |
-
|
| 9 |
-
import sys
|
| 10 |
-
import os
|
| 11 |
-
from pathlib import Path
|
| 12 |
-
|
| 13 |
-
# Add the current directory to Python path
|
| 14 |
-
sys.path.insert(0, str(Path(__file__).parent))
|
| 15 |
-
|
| 16 |
-
from DeepScholarBench import DeepScholarBench
|
| 17 |
-
import pandas as pd
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def load_papers_dataset():
|
| 21 |
-
"""Load the papers dataset."""
|
| 22 |
-
print("Loading papers dataset...")
|
| 23 |
-
|
| 24 |
-
# Create dataset builder
|
| 25 |
-
builder = DeepScholarBench(config_name="papers")
|
| 26 |
-
|
| 27 |
-
# Mock download manager for local files
|
| 28 |
-
class MockDownloadManager:
|
| 29 |
-
def download_and_extract(self, url_or_path):
|
| 30 |
-
return url_or_path
|
| 31 |
-
|
| 32 |
-
dl_manager = MockDownloadManager()
|
| 33 |
-
|
| 34 |
-
# Get split generators and load data
|
| 35 |
-
split_generators = builder._split_generators(dl_manager)
|
| 36 |
-
split_gen = split_generators[0] # Get train split
|
| 37 |
-
|
| 38 |
-
# Collect all examples
|
| 39 |
-
papers_data = []
|
| 40 |
-
for key, example in builder._generate_examples(
|
| 41 |
-
split_gen.gen_kwargs["filepath"],
|
| 42 |
-
split_gen.gen_kwargs["split"]
|
| 43 |
-
):
|
| 44 |
-
papers_data.append(example)
|
| 45 |
-
|
| 46 |
-
print(f"Loaded {len(papers_data)} papers")
|
| 47 |
-
return papers_data
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
def load_citations_dataset():
|
| 51 |
-
"""Load the citations dataset."""
|
| 52 |
-
print("Loading citations dataset...")
|
| 53 |
-
|
| 54 |
-
# Create dataset builder
|
| 55 |
-
builder = DeepScholarBench(config_name="citations")
|
| 56 |
-
|
| 57 |
-
# Mock download manager for local files
|
| 58 |
-
class MockDownloadManager:
|
| 59 |
-
def download_and_extract(self, url_or_path):
|
| 60 |
-
return url_or_path
|
| 61 |
-
|
| 62 |
-
dl_manager = MockDownloadManager()
|
| 63 |
-
|
| 64 |
-
# Get split generators and load data
|
| 65 |
-
split_generators = builder._split_generators(dl_manager)
|
| 66 |
-
split_gen = split_generators[0] # Get train split
|
| 67 |
-
|
| 68 |
-
# Collect all examples
|
| 69 |
-
citations_data = []
|
| 70 |
-
for key, example in builder._generate_examples(
|
| 71 |
-
split_gen.gen_kwargs["filepath"],
|
| 72 |
-
split_gen.gen_kwargs["split"]
|
| 73 |
-
):
|
| 74 |
-
citations_data.append(example)
|
| 75 |
-
|
| 76 |
-
print(f"Loaded {len(citations_data)} citations")
|
| 77 |
-
return citations_data
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
def load_important_citations_dataset():
|
| 81 |
-
"""Load the important citations dataset."""
|
| 82 |
-
print("Loading important citations dataset...")
|
| 83 |
-
|
| 84 |
-
# Create dataset builder
|
| 85 |
-
builder = DeepScholarBench(config_name="important_citations")
|
| 86 |
-
|
| 87 |
-
# Mock download manager for local files
|
| 88 |
-
class MockDownloadManager:
|
| 89 |
-
def download_and_extract(self, url_or_path):
|
| 90 |
-
return url_or_path
|
| 91 |
-
|
| 92 |
-
dl_manager = MockDownloadManager()
|
| 93 |
-
|
| 94 |
-
# Get split generators and load data
|
| 95 |
-
split_generators = builder._split_generators(dl_manager)
|
| 96 |
-
split_gen = split_generators[0] # Get train split
|
| 97 |
-
|
| 98 |
-
# Collect all examples
|
| 99 |
-
important_citations_data = []
|
| 100 |
-
for key, example in builder._generate_examples(
|
| 101 |
-
split_gen.gen_kwargs["filepath"],
|
| 102 |
-
split_gen.gen_kwargs["split"]
|
| 103 |
-
):
|
| 104 |
-
important_citations_data.append(example)
|
| 105 |
-
|
| 106 |
-
print(f"Loaded {len(important_citations_data)} important citations")
|
| 107 |
-
return important_citations_data
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
def main():
|
| 111 |
-
"""Main example function."""
|
| 112 |
-
print("DeepScholarBench Dataset - Usage Example")
|
| 113 |
-
print("=" * 50)
|
| 114 |
-
|
| 115 |
-
# Load datasets
|
| 116 |
-
papers = load_papers_dataset()
|
| 117 |
-
citations = load_citations_dataset()
|
| 118 |
-
important_citations = load_important_citations_dataset()
|
| 119 |
-
|
| 120 |
-
print("\n📊 Dataset Statistics:")
|
| 121 |
-
print(f" - Papers: {len(papers)}")
|
| 122 |
-
print(f" - Citations: {len(citations)}")
|
| 123 |
-
print(f" - Important Citations: {len(important_citations)}")
|
| 124 |
-
|
| 125 |
-
# Show sample paper
|
| 126 |
-
if papers:
|
| 127 |
-
sample_paper = papers[0]
|
| 128 |
-
print(f"\n📄 Sample Paper:")
|
| 129 |
-
print(f" - Title: {sample_paper['title']}")
|
| 130 |
-
print(f" - ArXiv ID: {sample_paper['arxiv_id']}")
|
| 131 |
-
print(f" - Authors: {sample_paper['authors'][:100]}...")
|
| 132 |
-
print(f" - Abstract: {sample_paper['abstract'][:200]}...")
|
| 133 |
-
|
| 134 |
-
# Show sample citation
|
| 135 |
-
if citations:
|
| 136 |
-
sample_citation = citations[0]
|
| 137 |
-
print(f"\n📚 Sample Citation:")
|
| 138 |
-
print(f" - Parent Paper: {sample_citation['parent_paper_title']}")
|
| 139 |
-
print(f" - Cited Paper: {sample_citation['cited_paper_title']}")
|
| 140 |
-
print(f" - Has Metadata: {sample_citation['has_metadata']}")
|
| 141 |
-
print(f" - Is ArXiv Paper: {sample_citation['is_arxiv_paper']}")
|
| 142 |
-
|
| 143 |
-
# Show sample important citation
|
| 144 |
-
if important_citations:
|
| 145 |
-
sample_important_citation = important_citations[0]
|
| 146 |
-
print(f"\n⭐ Sample Important Citation:")
|
| 147 |
-
print(f" - Parent Paper: {sample_important_citation['parent_paper_title']}")
|
| 148 |
-
print(f" - Cited Paper: {sample_important_citation['cited_paper_title']}")
|
| 149 |
-
print(f" - Has Metadata: {sample_important_citation['has_metadata']}")
|
| 150 |
-
print(f" - Is ArXiv Paper: {sample_important_citation['is_arxiv_paper']}")
|
| 151 |
-
|
| 152 |
-
# Convert to pandas for easier analysis
|
| 153 |
-
print(f"\n🐼 Converting to Pandas DataFrames...")
|
| 154 |
-
papers_df = pd.DataFrame(papers)
|
| 155 |
-
citations_df = pd.DataFrame(citations)
|
| 156 |
-
important_citations_df = pd.DataFrame(important_citations)
|
| 157 |
-
|
| 158 |
-
print(f" - Papers DataFrame: {papers_df.shape}")
|
| 159 |
-
print(f" - Citations DataFrame: {citations_df.shape}")
|
| 160 |
-
print(f" - Important Citations DataFrame: {important_citations_df.shape}")
|
| 161 |
-
|
| 162 |
-
# Show some analysis
|
| 163 |
-
print(f"\n📈 Quick Analysis:")
|
| 164 |
-
print(f" - Unique parent papers in citations: {citations_df['parent_paper_arxiv_id'].nunique()}")
|
| 165 |
-
print(f" - Citations with metadata: {citations_df['has_metadata'].sum()}")
|
| 166 |
-
print(f" - ArXiv citations: {citations_df['is_arxiv_paper'].sum()}")
|
| 167 |
-
print(f" - Unique parent papers in important citations: {important_citations_df['parent_paper_arxiv_id'].nunique()}")
|
| 168 |
-
print(f" - Important citations with metadata: {important_citations_df['has_metadata'].sum()}")
|
| 169 |
-
print(f" - ArXiv important citations: {important_citations_df['is_arxiv_paper'].sum()}")
|
| 170 |
-
|
| 171 |
-
return papers_df, citations_df, important_citations_df
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
if __name__ == "__main__":
|
| 175 |
-
papers_df, citations_df, important_citations_df = main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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