Datasets:

ArXiv:
License:
File size: 2,424 Bytes
585fe1b
 
 
91ebc59
585fe1b
 
 
 
 
 
 
 
 
 
2cb7d00
585fe1b
 
 
 
 
 
 
 
 
 
 
 
 
 
91ebc59
585fe1b
 
 
 
 
 
 
91ebc59
 
585fe1b
 
 
 
 
 
 
 
 
 
 
91ebc59
 
 
 
 
585fe1b
 
 
 
91ebc59
 
1012c0f
91ebc59
 
 
 
 
 
 
 
585fe1b
 
 
 
 
 
 
 
 
 
91ebc59
 
585fe1b
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
from collections import Counter, defaultdict

from datasets import load_dataset, DownloadMode
import matplotlib.pyplot as plt
from tqdm import tqdm

from project_settings import project_path


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("--dataset_name", default="tatoeba", type=str)
    parser.add_argument(
        "--dataset_cache_dir",
        default=(project_path / "hub_datasets").as_posix(),
        type=str
    )
    args = parser.parse_args()
    return args


def main():
    args = get_args()

    dataset = load_dataset(
        "../language_identification.py",
        name=args.dataset_name,
        split="train",
        cache_dir=args.dataset_cache_dir,
        # download_mode=DownloadMode.FORCE_REDOWNLOAD
    )

    counter1 = Counter()
    counter2 = Counter()
    examples = defaultdict(list)
    examples_counter = defaultdict(int)
    for sample in tqdm(dataset):
        text = sample["text"]
        language = sample["language"]

        text_length = len(text)
        text_length_round = int(text_length / 10) * 10
        text_length_round = 200 if text_length_round > 200 else text_length_round

        counter1.update([language])
        counter2.update([text_length_round])

        if examples_counter[language] < 3:
            examples[language].append(text)
            examples_counter[language] += 1

    print("\n")
    print("语种数量:")
    for k, v in counter1.most_common():
        print("{}: {}".format(k, v))

    print("\n")
    print("样本示例:")
    print("\n")
    print("| 数据 | 语种 | 样本 |")
    print("| :---: | :---: | :---: |")
    for language, text_list in examples.items():
        for text in text_list:
            row = "| {} | {} | {} |".format(args.dataset_name, language, text)
            print(row)

    print("\n")
    print("文本长度:")
    counter2 = list(sorted(counter2.items(), key=lambda x: x[0]))
    x = [item[0] for item in counter2]
    y = [item[1] for item in counter2]

    for k, v in counter2:
        text_length_range = "{}-{}".format(k, k+10)
        print("{}: {}".format(text_length_range, v))

    plt.plot(x, y)
    image_file = project_path / "docs/picture/{}_text_length.jpg".format(args.dataset_name)
    plt.savefig(image_file.as_posix())
    plt.show()

    return


if __name__ == "__main__":
    main()