Skip to content

Commit

Permalink
More score parsing improvements (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitead authored Dec 5, 2023
1 parent 5b622dd commit 97a99b7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
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

0 comments on commit 97a99b7

Please sign in to comment.