Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

load_ner_dataset.py 1.4 KB

You have to be logged in to leave a comment. Sign In
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
  1. def parse_single_line(line):
  2. split = line.split()
  3. return (split[0], split[-1])
  4. def load_ner_dataset(path):
  5. with open(path, "r") as f:
  6. new_line = f.readline()
  7. sentences = []
  8. while new_line:
  9. if new_line == "\n":
  10. new_line = f.readline()
  11. continue
  12. new_sentence = {"text":[], "tag":[]}
  13. while new_line and new_line != "\n":
  14. text, tag = parse_single_line(new_line)
  15. new_sentence["text"].append(text)
  16. new_sentence["tag"].append(tag)
  17. new_line = f.readline()
  18. sentences.append(new_sentence)
  19. new_line = f.readline()
  20. return sentences
  21. def load_ner_dataset_old(path):
  22. with open(path, "r") as f:
  23. new_line = f.readline()
  24. sentences = []
  25. while new_line:
  26. if new_line == "\n":
  27. new_line = f.readline()
  28. continue
  29. new_sentence = []
  30. while new_line and new_line != "\n":
  31. text, tag = parse_single_line(new_line)
  32. new_entry = {
  33. "text": text,
  34. "tag": tag,
  35. }
  36. new_sentence.append(new_entry)
  37. new_line = f.readline()
  38. sentences.append(new_sentence)
  39. new_line = f.readline()
  40. return sentences
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...