Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LongBench
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
thukeg
LongBench
Commits
556096be
Unverified
Commit
556096be
authored
2 months ago
by
Yushi Bai
Committed by
GitHub
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Delete eval.py
parent
55bd6779
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
eval.py
+0
-109
0 additions, 109 deletions
eval.py
with
0 additions
and
109 deletions
eval.py
deleted
100644 → 0
+
0
−
109
View file @
55bd6779
import
os
import
json
import
argparse
import
numpy
as
np
from
metrics
import
(
qa_f1_score
,
rouge_zh_score
,
qa_f1_zh_score
,
rouge_score
,
classification_score
,
retrieval_score
,
retrieval_zh_score
,
count_score
,
code_sim_score
,
)
dataset2metric
=
{
"
narrativeqa
"
:
qa_f1_score
,
"
qasper
"
:
qa_f1_score
,
"
multifieldqa_en
"
:
qa_f1_score
,
"
multifieldqa_zh
"
:
qa_f1_zh_score
,
"
hotpotqa
"
:
qa_f1_score
,
"
2wikimqa
"
:
qa_f1_score
,
"
musique
"
:
qa_f1_score
,
"
dureader
"
:
rouge_zh_score
,
"
gov_report
"
:
rouge_score
,
"
qmsum
"
:
rouge_score
,
"
multi_news
"
:
rouge_score
,
"
vcsum
"
:
rouge_zh_score
,
"
trec
"
:
classification_score
,
"
triviaqa
"
:
qa_f1_score
,
"
samsum
"
:
rouge_score
,
"
lsht
"
:
classification_score
,
"
passage_retrieval_en
"
:
retrieval_score
,
"
passage_count
"
:
count_score
,
"
passage_retrieval_zh
"
:
retrieval_zh_score
,
"
lcc
"
:
code_sim_score
,
"
repobench-p
"
:
code_sim_score
,
}
def
parse_args
(
args
=
None
):
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
--model
'
,
type
=
str
,
default
=
None
)
parser
.
add_argument
(
'
--e
'
,
action
=
'
store_true
'
,
help
=
"
Evaluate on LongBench-E
"
)
return
parser
.
parse_args
(
args
)
def
scorer_e
(
dataset
,
predictions
,
answers
,
lengths
,
all_classes
):
scores
=
{
"
0-4k
"
:
[],
"
4-8k
"
:
[],
"
8k+
"
:
[]}
for
(
prediction
,
ground_truths
,
length
)
in
zip
(
predictions
,
answers
,
lengths
):
score
=
0.
if
dataset
in
[
"
trec
"
,
"
triviaqa
"
,
"
samsum
"
,
"
lsht
"
]:
prediction
=
prediction
.
lstrip
(
'
\n
'
).
split
(
'
\n
'
)[
0
]
for
ground_truth
in
ground_truths
:
score
=
max
(
score
,
dataset2metric
[
dataset
](
prediction
,
ground_truth
,
all_classes
=
all_classes
))
if
length
<
4000
:
scores
[
"
0-4k
"
].
append
(
score
)
elif
length
<
8000
:
scores
[
"
4-8k
"
].
append
(
score
)
else
:
scores
[
"
8k+
"
].
append
(
score
)
for
key
in
scores
.
keys
():
scores
[
key
]
=
round
(
100
*
np
.
mean
(
scores
[
key
]),
2
)
return
scores
def
scorer
(
dataset
,
predictions
,
answers
,
all_classes
):
total_score
=
0.
for
(
prediction
,
ground_truths
)
in
zip
(
predictions
,
answers
):
score
=
0.
if
dataset
in
[
"
trec
"
,
"
triviaqa
"
,
"
samsum
"
,
"
lsht
"
]:
prediction
=
prediction
.
lstrip
(
'
\n
'
).
split
(
'
\n
'
)[
0
]
for
ground_truth
in
ground_truths
:
score
=
max
(
score
,
dataset2metric
[
dataset
](
prediction
,
ground_truth
,
all_classes
=
all_classes
))
total_score
+=
score
return
round
(
100
*
total_score
/
len
(
predictions
),
2
)
if
__name__
==
'
__main__
'
:
args
=
parse_args
()
scores
=
dict
()
if
args
.
e
:
path
=
f
"
pred_e/
{
args
.
model
}
/
"
else
:
path
=
f
"
pred/
{
args
.
model
}
/
"
all_files
=
os
.
listdir
(
path
)
print
(
"
Evaluating on:
"
,
all_files
)
for
filename
in
all_files
:
if
not
filename
.
endswith
(
"
jsonl
"
):
continue
predictions
,
answers
,
lengths
=
[],
[],
[]
dataset
=
filename
.
split
(
'
.
'
)[
0
]
with
open
(
f
"
{
path
}{
filename
}
"
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
f
:
for
line
in
f
:
data
=
json
.
loads
(
line
)
predictions
.
append
(
data
[
"
pred
"
])
answers
.
append
(
data
[
"
answers
"
])
all_classes
=
data
[
"
all_classes
"
]
if
"
length
"
in
data
:
lengths
.
append
(
data
[
"
length
"
])
if
args
.
e
:
score
=
scorer_e
(
dataset
,
predictions
,
answers
,
lengths
,
all_classes
)
else
:
score
=
scorer
(
dataset
,
predictions
,
answers
,
all_classes
)
scores
[
dataset
]
=
score
if
args
.
e
:
out_path
=
f
"
pred_e/
{
args
.
model
}
/result.json
"
else
:
out_path
=
f
"
pred/
{
args
.
model
}
/result.json
"
with
open
(
out_path
,
"
w
"
)
as
f
:
json
.
dump
(
scores
,
f
,
ensure_ascii
=
False
,
indent
=
4
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment