ZoneTwelve commited on
Commit
5da6fa2
·
1 Parent(s): 4e2027c

Add processing tools.

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__
loader.py → dataset_loader.py RENAMED
@@ -4,9 +4,9 @@ from datasets import load_dataset
4
  version = 'original' # latest version of this dataset
5
 
6
  # Load the dataset with version control
7
- dataset = load_dataset('json', data_files={'train': 'original/train.jsonl',
8
- 'validation': 'original/valid.jsonl',
9
- 'test': 'original/test.jsonl'},
10
  version=version)
11
 
12
  # Access the data
@@ -16,7 +16,7 @@ test_dataset = dataset['test']
16
 
17
  # Example usage
18
  for example in train_dataset:
19
- print(example['text'])
20
  break
21
 
22
  # Get the dataset version
 
4
  version = 'original' # latest version of this dataset
5
 
6
  # Load the dataset with version control
7
+ dataset = load_dataset('json', data_files={'train': f'{version}/train.jsonl',
8
+ 'validation': f'{version}/valid.jsonl',
9
+ 'test': f'{version}/test.jsonl'},
10
  version=version)
11
 
12
  # Access the data
 
16
 
17
  # Example usage
18
  for example in train_dataset:
19
+ print(example['user'], example['assistant'])
20
  break
21
 
22
  # Get the dataset version
functions/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from . import regular
functions/regular.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ import pandas as pd
4
+ import re
5
+
6
+ def process(df: pd.DataFrame) -> pd.DataFrame:
7
+
8
+ pattern = r'<\|im_start\|>(\w+)\n(.*?)<\|im_end\|>'
9
+
10
+ def process_text(text):
11
+ matches = re.findall(pattern, text, re.DOTALL)
12
+ return dict(matches)
13
+
14
+ result = df['text'].apply(process_text)
15
+ return pd.DataFrame(result.tolist())
16
+
17
+
18
+ def main(file: str = None) -> None:
19
+ if file != None:
20
+ df = pd.read_json(file, lines=True)
21
+ result = process(df)
22
+ print(result)
23
+ else:
24
+ data = {
25
+ "text": [
26
+ '<|im_start|>system You are a helpful assistant<|im_end|> <|im_start|>user "阿猛,你觉得做视频最重要的是什么,除了内容好,还有什么能让视频更吸引人呢?"<|im_end|> <|im_start|>assistant 视频做的很好,但美中不足的是。。。时长太短,不!够!看!<|im_end|>',
27
+ '<|im_start|>system You are a helpful assistant<|im_end|> <|im_start|>user "要如何學會加法"<|im_end|> <|im_start|>assistant 這個問題,我也不太會<|im_end|>',
28
+ ]
29
+ }
30
+ df = pd.DataFrame(data)
31
+ result = process(df)
32
+ print(result)
33
+
34
+ if __name__ == "__main__":
35
+ import fire
36
+ fire.Fire(main)
separation.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import functions
5
+ import pandas as pd
6
+
7
+ def main(
8
+ in_file: str,
9
+ out_file: str,
10
+ func: str = '',
11
+ ):
12
+ try:
13
+ # Default using jsonl
14
+ processor = getattr(functions, func)
15
+ df = pd.read_json(in_file, lines=True)
16
+ out = processor.process(df)
17
+ with open(out_file, 'w', encoding='utf-8') as file:
18
+ out.to_json(file, force_ascii=False, lines=True, orient='records')
19
+ except ValueError as e:
20
+ print(e)
21
+
22
+ if __name__ == '__main__':
23
+ import fire
24
+ fire.Fire(main)