Skip to content
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

A few proposed modifications #20

Merged
merged 6 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions factcheck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(
evidence_retrieval_model: str = None,
claim_verify_model: str = None,
api_config: dict = None,
num_seed_retries: int = 3,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow to modify num_retries while initing FactCheck class.

):
self.encoding = tiktoken.get_encoding("cl100k_base")

Expand Down Expand Up @@ -63,6 +64,7 @@ def __init__(
self.query_generator = QueryGenerator(llm_client=self.query_generator_model, prompt=self.prompt)
self.evidence_crawler = retriever_mapper(retriever_name=retriever)(api_config=self.api_config)
self.claimverify = ClaimVerify(llm_client=self.claim_verify_model, prompt=self.prompt)
self.num_seed_retries = num_seed_retries

logger.info("===Sub-modules Init Finished===")

Expand All @@ -73,15 +75,15 @@ def load_config(self, api_config: dict) -> None:
def check_response(self, response: str):
st_time = time.time()
# step 1
claims = self.decomposer.getclaims(doc=response)
claims = self.decomposer.getclaims(doc=response, num_retries=self.num_seed_retries)
for i, claim in enumerate(claims):
logger.info(f"== response claims {i}: {claim}")

# step 2
(
checkworthy_claims,
pairwise_checkworthy,
) = self.checkworthy.identify_checkworthiness(claims)
) = self.checkworthy.identify_checkworthiness(claims, num_retries=self.num_seed_retries)
for i, claim in enumerate(checkworthy_claims):
logger.info(f"== Check-worthy claims {i}: {claim}")

Expand Down
11 changes: 8 additions & 3 deletions factcheck/core/Retriever/serper_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def _retrieve_evidence_4_all_claim(self, query_list: list[str], top_k: int = 5,

# get the results for queries with an answer box
query_url_dict = {}
url_to_date = {}
_snippet_to_check = []
for i, (query, result) in enumerate(zip(query_list, serper_response.json())):
if query != result.get("searchParameters").get("q"):
Expand All @@ -85,13 +86,17 @@ def _retrieve_evidence_4_all_claim(self, query_list: list[str], top_k: int = 5,
}
else:
results = result.get("organic", [])[:top_k] # Choose top 5 result
merge_evidence_text = [f"Text: {_result['snippet']} \n Source: {_result['link']}" for _result in results]
merge_evidence_text = [re.sub(r"\n+", "\n", evidence) for evidence in merge_evidence_text]
merge_evidence_text = [
f"Text: {_result['snippet']} \n Source: {_result['link']} \n Date: {_result.get('date', 'Unknown')}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include the date of the result in the prompt. Thanks to this, OFV can verify claims such as "Did X happen before Y?"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! The inclusion of the date as a separate factor might be helpful, but I suspect it is not essential. In your example, "X happens before Y," we would expect the generated queries to be like ["When did X happen?", "When did Y happen?"]. Given such queries, retrieved evidence is expected to be sufficient to solve this problem.

Prompt for query generation:
https://github.com/Libr-AI/OpenFactVerification/blob/f620f6e5879ee1219661afc749c9fd8f658b194b/factcheck/utils/prompt/chatgpt_prompt.py#L43C1-L62

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry for late reply, I was on vacation.

Unfortunately, not all articles come with clear dates in them. But Serp can return their creation date anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be available behind a flag in FactCheck's initialisation?

for _result in results
]
evidences[i] = {
"text": "\n\n".join(merge_evidence_text),
"url": "Multiple",
}

# Save date for each url
url_to_date.update({result.get("link"): result.get("date") for result in results})
# Save query-url pair, 1 query may have multiple urls
query_url_dict.update({query: [result.get("link") for result in results]})
_snippet_to_check += [result["snippet"] for result in results]
Expand Down Expand Up @@ -157,7 +162,7 @@ def bs4_parse_text(response, snippet, flag):
for _query in query_snippet_dict.keys():
_query_index = query_list.index(_query)
_snippet_list = query_snippet_dict[_query]
merge_evidence_text = [f"Text: {snippet} \n Source: {_url}" for snippet, _url in zip(_snippet_list, url_to_check)]
merge_evidence_text = [f"Text: {snippet} \n Source: {_url} \n Date: {url_to_date.get(_url, 'Unknown')}" for snippet, _url in zip(_snippet_list, url_to_check)]
merge_evidence_text = [re.sub(r"\n+", "\n", evidence) for evidence in merge_evidence_text]
evidences[_query_index] = {
"text": "\n\n".join(merge_evidence_text),
Expand Down
Loading