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
ModelZoo
ChatGLM3-6B_pytorch
Commits
7769bf8b
Commit
7769bf8b
authored
May 10, 2024
by
lvzhen
Browse files
Update finetune_demo/process.py
parent
09e6ef0b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
finetune_demo/process.py
finetune_demo/process.py
+41
-0
No files found.
finetune_demo/process.py
0 → 100644
View file @
7769bf8b
import
json
from
typing
import
Union
from
pathlib
import
Path
def
_resolve_path
(
path
:
Union
[
str
,
Path
])
->
Path
:
return
Path
(
path
).
expanduser
().
resolve
()
def
_mkdir
(
dir_name
:
Union
[
str
,
Path
]):
dir_name
=
_resolve_path
(
dir_name
)
if
not
dir_name
.
is_dir
():
dir_name
.
mkdir
(
parents
=
True
,
exist_ok
=
False
)
def
convert_adgen
(
data_dir
:
Union
[
str
,
Path
],
save_dir
:
Union
[
str
,
Path
]):
def
_convert
(
in_file
:
Path
,
out_file
:
Path
):
_mkdir
(
out_file
.
parent
)
with
open
(
in_file
,
encoding
=
'utf-8'
)
as
fin
:
with
open
(
out_file
,
'wt'
,
encoding
=
'utf-8'
)
as
fout
:
for
line
in
fin
:
dct
=
json
.
loads
(
line
)
sample
=
{
'conversations'
:
[{
'role'
:
'user'
,
'content'
:
dct
[
'content'
]},
{
'role'
:
'assistant'
,
'content'
:
dct
[
'summary'
]}]}
fout
.
write
(
json
.
dumps
(
sample
,
ensure_ascii
=
False
)
+
'
\n
'
)
data_dir
=
_resolve_path
(
data_dir
)
save_dir
=
_resolve_path
(
save_dir
)
train_file
=
data_dir
/
'train.json'
if
train_file
.
is_file
():
out_file
=
save_dir
/
train_file
.
relative_to
(
data_dir
)
_convert
(
train_file
,
out_file
)
dev_file
=
data_dir
/
'dev.json'
if
dev_file
.
is_file
():
out_file
=
save_dir
/
dev_file
.
relative_to
(
data_dir
)
_convert
(
dev_file
,
out_file
)
convert_adgen
(
'data/AdvertiseGen'
,
'data/AdvertiseGen_fix'
)
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