Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
opencompass
Commits
749e4cea
Unverified
Commit
749e4cea
authored
May 24, 2024
by
yaoyingyy
Committed by
GitHub
May 24, 2024
Browse files
[Fix] temporary files using tempfile (#1186)
Co-authored-by:
yaoying
<
yaoying@kingsoft.com
>
parent
5eb8f14d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
+15
-13
opencompass/datasets/lawbench/evaluation_functions/wsjd.py
opencompass/datasets/lawbench/evaluation_functions/wsjd.py
+15
-13
No files found.
opencompass/datasets/lawbench/evaluation_functions/wsjd.py
View file @
749e4cea
import
re
import
re
import
os
import
os
import
subprocess
import
subprocess
import
tempfile
"""
"""
Task: legal document grammar correction
Task: legal document grammar correction
...
@@ -30,21 +31,22 @@ def compute_wsjd(data_dict):
...
@@ -30,21 +31,22 @@ def compute_wsjd(data_dict):
now_path
=
os
.
path
.
abspath
(
os
.
getcwd
())
now_path
=
os
.
path
.
abspath
(
os
.
getcwd
())
utils_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
__file__
,
'..'
,
'..'
,
'utils'
))
utils_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
__file__
,
'..'
,
'..'
,
'utils'
))
uid
=
os
.
getuid
()
os
.
chdir
(
utils_path
)
os
.
chdir
(
utils_path
)
with
open
(
f
'/tmp/tmp_pred_
{
uid
}
.para'
,
'w'
)
as
f
:
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'w'
)
as
tmp_pred_file
,
\
f
.
writelines
(
preds
)
tempfile
.
NamedTemporaryFile
(
delete
=
False
,
mode
=
'w'
)
as
tmp_gold_file
:
with
open
(
f
'/tmp/tmp_gold_
{
uid
}
.para'
,
'w'
)
as
f
:
tmp_pred_file
.
writelines
(
preds
)
f
.
writelines
(
golds
)
tmp_gold_file
.
writelines
(
golds
)
os
.
environ
[
'KMP_DUPLICATE_LIB_OK'
]
=
'True'
os
.
system
(
f
'python3 parallel_to_m2.py -f /tmp/tmp_pred_
{
uid
}
.para -o /tmp/tmp_pred_
{
uid
}
.para.m2 -g char'
)
os
.
environ
[
'KMP_DUPLICATE_LIB_OK'
]
=
'True'
os
.
system
(
f
'python3 parallel_to_m2.py -f /tmp/tmp_gold_
{
uid
}
.para -o /tmp/tmp_gold_
{
uid
}
.para.m2 -g char'
)
os
.
system
(
f
'python3 parallel_to_m2.py -f
{
tmp_pred_file
.
name
}
-o
{
tmp_pred_file
.
name
}
.m2 -g char'
)
output
=
subprocess
.
check_output
(
f
"python3 compare_m2_for_evaluation.py -hyp /tmp/tmp_pred_
{
uid
}
.para.m2 -ref /tmp/tmp_gold_
{
uid
}
.para.m2"
,
shell
=
True
)
os
.
system
(
f
'python3 parallel_to_m2.py -f
{
tmp_gold_file
.
name
}
-o
{
tmp_gold_file
.
name
}
.m2 -g char'
)
output
=
subprocess
.
check_output
(
f
"python3 compare_m2_for_evaluation.py -hyp
{
tmp_pred_file
.
name
}
.m2 -ref
{
tmp_gold_file
.
name
}
.m2"
,
shell
=
True
)
score
=
float
(
output
.
decode
().
split
(
'
\t
'
)[
-
1
].
split
(
'
\n
'
)[
0
])
score
=
float
(
output
.
decode
().
split
(
'
\t
'
)[
-
1
].
split
(
'
\n
'
)[
0
])
#remove prediction files
#remove prediction files
os
.
remove
(
f
'/tmp/
tmp_pred_
{
uid
}
.para'
)
os
.
remove
(
tmp_pred_
file
.
name
)
os
.
remove
(
f
'/tmp/
tmp_gold_
{
uid
}
.para'
)
os
.
remove
(
tmp_gold_
file
.
name
)
os
.
remove
(
f
'/tmp/
tmp_pred_
{
uid
}
.para
.m2
'
)
os
.
remove
(
f
"
{
tmp_pred_
file
.
name
}
.m2
"
)
os
.
remove
(
f
'/tmp/
tmp_gold_
{
uid
}
.para
.m2
'
)
os
.
remove
(
f
"
{
tmp_gold_
file
.
name
}
.m2
"
)
os
.
chdir
(
now_path
)
os
.
chdir
(
now_path
)
return
{
"score"
:
score
}
return
{
"score"
:
score
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment