-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Draft: TXT2KG
w/ hotpot_qa.py
and tech_qa.py
examples
#9846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 17 commits
Commits
Show all changes
327 commits
Select commit
Hold shift + click to select a range
703c83d
speedup indexing
puririshi98 538eeba
speedup indexing
puririshi98 f1a3e7a
speedup indexing
puririshi98 9be12dc
speedup indexing
puririshi98 3a0bee2
speedup indexing
puririshi98 1cc5091
speedup indexing
puririshi98 845f186
debug
puririshi98 40caac7
debug
puririshi98 f4a5edc
debug
puririshi98 218f418
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 741a750
debug
puririshi98 0f46bec
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 14e962d
debug
puririshi98 8dd0b70
debug
puririshi98 3b6ecbe
Update hotpot_qa.py
puririshi98 b0075cd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0716668
debug
puririshi98 1ecdaa7
debug
puririshi98 21c5875
debug
puririshi98 88ce2b8
debug
puririshi98 1d3030e
debug
puririshi98 454bf0a
debug
puririshi98 e6057a8
debug
puririshi98 3841de2
debug
puririshi98 9c2850b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ff63faf
debug
puririshi98 3acba5e
debug
puririshi98 4b1b06b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c207009
debug
puririshi98 4d71797
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 c2670ed
debug
puririshi98 19b91b3
debug
puririshi98 68833b2
debug
puririshi98 8c9a041
debug
puririshi98 0d3318b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f0d3710
debug
puririshi98 f959254
debug
puririshi98 fa90418
debug
puririshi98 bf2e13e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 34fb3da
debug
puririshi98 803c29b
debug
puririshi98 00d1e7e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fd9f099
debug
puririshi98 518c5b5
debug
puririshi98 3632cec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3a7d7b2
debug
puririshi98 1ca06cd
debug
puririshi98 231e9f4
debug
puririshi98 17933a0
debug
puririshi98 7db3248
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7b2d2f6
debug
puririshi98 673f8fb
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 fc18b59
debug
puririshi98 9a09c98
debug
puririshi98 955304e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bb6512a
debug
puririshi98 976d175
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 b6d80b0
debug
puririshi98 eba0173
debug
puririshi98 eeb2a43
debug
puririshi98 954490e
debug
puririshi98 8ac4974
debug
puririshi98 d1c9e13
debug
puririshi98 c3dc6f5
debug
puririshi98 8579159
debug
puririshi98 2670959
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 961ff44
debug
puririshi98 44e676a
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 644bcc3
debug
puririshi98 44a17f3
debug
puririshi98 105783c
debug
puririshi98 c8415c1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 628324d
debug
puririshi98 a815db3
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 1c75a75
debug
puririshi98 217ec15
debug
puririshi98 b6aa2c3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1f15921
debug
puririshi98 bb5d4b1
debug
puririshi98 f077e26
debug
puririshi98 7a68eb6
debug
puririshi98 777c1d1
debug
puririshi98 571e09c
debug
puririshi98 5aabf3c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b1c1dc4
debug
puririshi98 2eae672
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 d7dab0e
debug
puririshi98 5f24624
debug
puririshi98 ab187ee
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6c2cf17
debug
puririshi98 4a83a6a
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 335d628
debug
puririshi98 9a3967a
debug
puririshi98 9747aa2
debug
puririshi98 5a32171
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8185846
debug
puririshi98 4e702da
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 0fffa39
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5b2f845
debug
puririshi98 8ac7adc
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 a00cc1b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d7a78db
debug
puririshi98 fe7e3e5
debug
puririshi98 9d873f4
debug
puririshi98 571b0e7
debug
puririshi98 e28c88f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 76db078
debug
puririshi98 f1815ee
debug
puririshi98 8359d78
debug
puririshi98 ba911b8
debug
puririshi98 dcf2cc0
debug
puririshi98 767526e
debug
puririshi98 1418cdc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a5bd9d7
debug
puririshi98 bb7d0f9
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 bb26487
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 04519b0
debug
puririshi98 ae84691
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 a760b5a
debug
puririshi98 f9e73bf
debug
puririshi98 e1f369a
debug
puririshi98 ef925a8
debug
puririshi98 6350622
debug
puririshi98 2020bd0
debug
puririshi98 675e744
system works pretty well now, adding approx recall
puririshi98 497e65b
debug
puririshi98 8371afb
debug
puririshi98 0a0a090
debug
puririshi98 2d00ed2
debug
puririshi98 cdc86cb
debug
puririshi98 57b61c7
debug
puririshi98 f0f8ae9
debug
puririshi98 9f16ec4
debug
puririshi98 fbc8243
final fix
puririshi98 c96e9d3
removed prints, done debugging. will tune hyperparams for retriever p…
puririshi98 c76686e
removed prints, done debugging. will tune hyperparams for retriever p…
puririshi98 fa445a5
Merge branch 'master' into rebase-txt2kg
puririshi98 3ecccda
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 63ea8b2
removing unneeded comments
puririshi98 2c8ec46
cleaning
puririshi98 7954786
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5ab3299
Update graph_store.py
puririshi98 f9c0e9c
clean
puririshi98 423891d
improving defaults for hotpotQA retrieval, will continue to tune afte…
puririshi98 bb18b77
updating txt2kg system prompt, last sentence caused wierd behavior
puririshi98 5addd93
Update hotpot_qa.py
puririshi98 a5faf9b
Update hotpot_qa.py
puririshi98 a7e044b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8f984d1
Update txt2kg.py
puririshi98 d44f280
fixing typo
puririshi98 6e3aefc
Update backend_utils.py
puririshi98 9e8d5cb
fix for bellow issue
puririshi98 4eb0ed8
Update backend_utils.py
puririshi98 fa5c659
Update txt2kg.py
puririshi98 0969d67
commenting and usability
puririshi98 d5e49a6
commenting and usability
puririshi98 0cc3ef5
commenting and usability
puririshi98 0f19922
skip pcst for bad graphs
puririshi98 4f28162
Merge branch 'master' into rebase-txt2kg
puririshi98 e7529a6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ec702db
commenting and usability
puririshi98 3a7cc3f
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 29523fe
commenting and usability
puririshi98 3904f51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1ed1c18
commenting and usability
puririshi98 718d82f
commenting and usability
puririshi98 ff9c3fa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5521aea
commenting and usability
puririshi98 6de0788
commenting and usability
puririshi98 7309bc6
commenting and usability
puririshi98 3c93c41
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 88a7986
drafting techqa
puririshi98 8f7a7dd
drafting techqa
puririshi98 6c9a0db
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c1aad3f
drafting techqa
puririshi98 dd026fb
drafting techqa
puririshi98 1deb4f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e1581e1
drafting techqa
puririshi98 400eea0
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 0cbd525
drafting techqa
puririshi98 2484d2d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] afb0ac5
drafting techqa
puririshi98 741bf2e
drafting techqa
puririshi98 f8c0ee1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c7b5462
drafting techqa
puririshi98 b491aae
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 75157bd
drafting techqa
puririshi98 04c80a0
drafting techqa
puririshi98 2826852
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0b081fe
drafting techqa
puririshi98 3bba220
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f0aec29
drafting techqa
puririshi98 db6cee7
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 6bbb6ae
drafting techqa
puririshi98 9cf3a89
drafting techqa
puririshi98 451ae4d
add techqa to Readme
puririshi98 2111b02
ai cleanup (#9970)
puririshi98 2ff6a85
ai cleanup for utils (#9971)
puririshi98 afe44d6
Merge branch 'master' into rebase-txt2kg
puririshi98 c7a5e4d
fix for "Note:"
puririshi98 024cabe
Merge branch 'master' into rebase-txt2kg
puririshi98 cdc492f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4693e53
Update txt2kg.py
puririshi98 cadaa9d
Add eval (#9976)
puririshi98 e92c0e7
Merge branch 'master' into rebase-txt2kg
puririshi98 8249ba1
Update examples/llm/hotpot_qa.py
puririshi98 f134106
address reviews
puririshi98 b9a55cf
Update hotpot_qa.py
puririshi98 3dbcf8f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2519e67
drafting
puririshi98 45214cd
drafting
puririshi98 8b77eaa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7747b12
drafting
puririshi98 5addc14
drafting
puririshi98 a38d489
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 45133b7
drafting
puririshi98 cae97e7
drafting
puririshi98 e109dc5
drafting
puririshi98 29109a4
drafting
puririshi98 3b92cf1
drafting
puririshi98 8712e8b
drafting
puririshi98 a1c0cc4
drafting
puririshi98 0f744a7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 98240cd
drafting
puririshi98 fb9e378
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 15fe2bd
drafting
puririshi98 941b745
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 473577d
drafting
puririshi98 0c664f1
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 055527b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 77d5951
drafting
puririshi98 db4a24a
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 d99a23c
drafting
puririshi98 c4400f1
drafting
puririshi98 10da58b
drafting
puririshi98 b977e9a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5240ca0
cleaning
puririshi98 4a2e86b
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 c3654c8
cleaning
puririshi98 8b8f00f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7bc4bcb
cleaning
puririshi98 f6c81f1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 906e82c
cleaning
puririshi98 cf6162c
Merge branch 'rebase-txt2kg' of https://github.com/pyg-team/pytorch_g…
puririshi98 a2ea3cd
cleaning
puririshi98 8883238
cleaning
puririshi98 11194ee
cleaning
puririshi98 ea15dc9
cleaning
puririshi98 87d7b70
cleaning
puririshi98 5d9b34e
Nim sent transformer and better comments for senttrans (#9990)
puririshi98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
# Examples for Co-training LLMs and GNNs | ||
|
||
| Example | Description | | ||
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| [`g_retriever.py`](./g_retriever.py) | Example for Retrieval-Augmented Generation (RAG) w/ GNN+LLM by co-training `LLAMA2` with `GAT` for answering questions based on knowledge graph information | | ||
| [`g_retriever_utils/`](./g_retriever_utils/) | Contains multiple scripts for benchmarking GRetriever's architecture and evaluating different retrieval methods. | | ||
| [`multihop_rag/`](./multihop_rag/) | Contains starter code and an example run for building a Multi-hop dataset using WikiHop5M and 2WikiMultiHopQA | | ||
| Example | Description | | ||
| -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| [`g_retriever.py`](./g_retriever.py) | Example for Retrieval-Augmented Generation (RAG) w/ GNN+LLM by co-training `LLAMA2` with `GAT` for answering questions based on knowledge graph information | | ||
| [`g_retriever_utils/`](./g_retriever_utils/) | Contains multiple scripts for benchmarking GRetriever's architecture and evaluating different retrieval methods. | | ||
|
||
| [`nvtx_examples/`](./nvtx_examples/) | Contains examples of how to wrap functions using the NVTX profiler for CUDA runtime analysis. | | ||
| [`molecule_gpt.py`](./molecule_gpt.py) | Example for MoleculeGPT: Instruction Following Large Language Models for Molecular Property Prediction | | ||
| [`glem.py`](./glem.py) | Example for [GLEM](https://arxiv.org/abs/2210.14709), a GNN+LLM co-training model via variational Expectation-Maximization (EM) framework on node classification tasks to achieve SOTA results | | ||
| [`git_mol.py`](./git_mol.py) | Example for GIT-Mol: A Multi-modal Large Language Model for Molecular Science with Graph, Image, and Text | | ||
| [`hotpot_qa.py`](./hotpot_qa.py) | Example for converting adapting the retrieval step of conventional Retrieval-Augmented Generation (RAG) for use with G-retriever, and how to approximate the precision/recall of a subgraph retrieval method. Uses the HotPotQA dataset as an example since it is multihop in nature. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import argparse | ||
import os | ||
from itertools import chain | ||
|
||
import datasets | ||
import torch | ||
from tqdm import tqdm | ||
|
||
from torch_geometric import seed_everything | ||
from torch_geometric.loader import RAGQueryLoader | ||
from torch_geometric.nn.nlp import TXT2KG, SentenceTransformer | ||
from torch_geometric.utils.rag.backend_utils import ( | ||
create_remote_backend_from_triplets, | ||
make_pcst_filter, | ||
preprocess_triplet, | ||
) | ||
from torch_geometric.utils.rag.feature_store import ( | ||
SentenceTransformerFeatureStore, | ||
) | ||
from torch_geometric.utils.rag.graph_store import NeighborSamplingRAGGraphStore | ||
|
||
if __name__ == '__main__': | ||
seed_everything(50) | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--NV_NIM_MODEL', type=str, | ||
default="nvidia/llama-3.1-nemotron-70b-instruct") | ||
parser.add_argument('--NV_NIM_KEY', type=str, default="") | ||
parser.add_argument('--local_lm', action="store_true") | ||
parser.add_argument('--percent_data', type=float, default=1.0) | ||
parser.add_argument( | ||
'--chunk_size', type=int, default=512, help= | ||
"When splitting context documents, the maximum number of characters per chunk." | ||
) | ||
parser.add_argument('--checkpointing', action="store_true") | ||
parser.add_argument('--verbose', action="store_true") | ||
args = parser.parse_args() | ||
assert args.percent_data <= 100 and args.percent_data > 0 | ||
if args.local_lm: | ||
kg_maker = TXT2KG( | ||
local_LM=True, | ||
chunk_size=args.chunk_size, | ||
) | ||
else: | ||
kg_maker = TXT2KG( | ||
NVIDIA_NIM_MODEL=args.NV_NIM_MODEL, | ||
NVIDIA_API_KEY=args.NV_NIM_KEY, | ||
chunk_size=args.chunk_size, | ||
) | ||
if os.path.exists("hotpot_kg.pt"): | ||
print("Re-using existing KG...") | ||
relevant_triples = torch.load("hotpot_kg.pt") | ||
elif os.path.exists("checkpoint_kg.pt"): | ||
print("Re-using existing checkpoint...") | ||
relevant_triples = torch.load("checkpoint_kg.pt") | ||
else: | ||
# Use training set for simplicity since our retrieval method is nonparametric | ||
raw_dataset = datasets.load_dataset('hotpotqa/hotpot_qa', 'fullwiki', | ||
trust_remote_code=True)["train"] | ||
# Build KG | ||
num_data_pts = len(raw_dataset) | ||
data_idxs = torch.randperm(num_data_pts)[0:int(num_data_pts * | ||
args.percent_data / | ||
100.0)] | ||
if args.checkpointing: | ||
five_percent = int(len(data_idxs) / 20) | ||
count = 0 | ||
for idx in tqdm(data_idxs, desc="Building KG"): | ||
data_point = raw_dataset[int(idx)] | ||
q = data_point["question"] | ||
a = data_point["answer"] | ||
context_doc = '' | ||
for i in data_point["context"]["sentences"]: | ||
for sentence in i: | ||
context_doc += sentence | ||
|
||
QA_pair = (q, a) | ||
kg_maker.add_doc_2_KG( | ||
txt=context_doc, | ||
QA_pair=QA_pair, | ||
) | ||
if args.checkpointing: | ||
count += 1 | ||
if count == five_percent: | ||
print("checkpointing...") | ||
count = 0 | ||
kg_maker.save_kg("checkpoint_kg.pt") | ||
kg_maker.save_kg("hotpot_kg.pt") | ||
if args.checkpointing: | ||
# delete checkpoint | ||
os.remove("checkpoint_kg.pt") | ||
|
||
relevant_triples = kg_maker.relevant_triples | ||
if args.local_lm: | ||
print("Total number of context characters parsed by LLM", | ||
kg_maker.total_chars_parsed) | ||
print( | ||
"Average number of context characters parsed by LLM per second=", | ||
kg_maker.avg_chars_parsed_per_sec) | ||
|
||
print("Size of KG (number of triples) =", | ||
sum([len(rel_trips) for rel_trips in relevant_triples.values()])) | ||
|
||
triples = list( | ||
chain.from_iterable(triple_set | ||
for triple_set in relevant_triples.values())) | ||
# debug | ||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | ||
model = SentenceTransformer( | ||
model_name='sentence-transformers/all-roberta-large-v1').to(device) | ||
fs, gs = create_remote_backend_from_triplets( | ||
triplets=triples, node_embedding_model=model, | ||
node_method_to_call="encode", path="backend", | ||
pre_transform=preprocess_triplet, node_method_kwargs={ | ||
"batch_size": min(len(triples), 256) | ||
}, graph_db=NeighborSamplingRAGGraphStore, | ||
feature_db=SentenceTransformerFeatureStore).load() | ||
query_loader = RAGQueryLoader( | ||
data=(fs, gs), seed_nodes_kwargs={"k_nodes": | ||
5}, seed_edges_kwargs={"k_edges": 5}, | ||
sampler_kwargs={"num_neighbors": [50] * 2}, | ||
local_filter=make_pcst_filter(triples, model)) | ||
""" | ||
approx precision = num_relevant_out_of_retrieved/num_retrieved_triples | ||
We will use precision as a proxy for recall. This is because for recall, | ||
we must know how many relevant triples exist for each question, | ||
but this is not known. | ||
""" | ||
precisions = [] | ||
for QA_pair in relevant_triplges.keys(): | ||
golden_triples = relevant_triples[QA_pair] | ||
q = QA_pair[0] | ||
retrieved_subgraph = query_loader.query(q) | ||
retrieved_triples = retrieved_subgraph.triples | ||
|
||
if args.verbose: | ||
print("Q=", q) | ||
print("A=", QA_pair[1]) | ||
print("retrieved_triples =", retrieved_triples) | ||
|
||
num_relevant_out_of_retrieved = float( | ||
sum([ | ||
int(bool(retrieved_triple in golden_triples)) | ||
for retrieved_triple in retrieved_triples | ||
])) | ||
precisions.append(num_relevant_out_of_retrieved / | ||
len(retrieved_triples)) | ||
approx_precision = sum(precisions) / len(precisions) | ||
print("approx_precision =", approx_precision) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.