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

More score parsing improvements #218

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions paperqa/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def make_chain(


def get_score(text: str) -> int:
# check for N/A
last_line = text.split("\n")[-1]
if "N/A" in last_line or "n/a" in last_line or "NA" in last_line:
return 0
score = re.search(r"[sS]core[:is\s]+([0-9]+)", text)
if not score:
score = re.search(r"\(([0-9])\w*\/", text)
Expand Down
2 changes: 1 addition & 1 deletion paperqa/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.13.3"
__version__ = "3.13.4"
32 changes: 32 additions & 0 deletions tests/test_paperqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,38 @@ def test_extract_score():

assert get_score(sample) == 3

sample = (
"The text mentions a work by Shozo Yokoyama titled "
'"Evolution of Dim-Light and Color Vision Pigments". '
"This work, published in the Annual Review of Genomics and "
"Human Genetics, discusses the evolution of human color vision. "
"However, the text does not provide specific details or findings "
"from Yokoyama's work. \n"
"Relevance Score: 7"
)

assert get_score(sample) == 7

sample = (
"The evolution of human color vision is "
"closely tied to theories about the nature "
"of light, dating back to the 17th to 19th "
"centuries. Initially, there was no clear distinction "
"between the properties of light, the eye and retina, "
"and color percepts. Major figures in science attempted "
"to resolve these issues, with physicists leading most "
"advances in color science into the 20th century. Prior "
"to Newton, colors were viewed as stages between black "
"and white. Newton was the first to describe colors in "
"a modern sense, using prisms to disperse light into "
"a spectrum of colors. He demonstrated that each color "
"band could not be further divided and that different "
"colors had different refrangibility. \n"
"Relevance Score: 9.5"
)

assert get_score(sample) == 9


def test_docs():
llm = OpenAI(client=None, temperature=0.1, model="text-ada-001")
Expand Down
Loading