1 Star 0 Fork 0

yasiping / BERT-NER

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
function_test.py 778 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhoukaiyin 提交于 2019-04-12 09:58 . BERT-NER Version 2
#! usr/bin/env python3
# -*- coding:utf-8 -*-
"""
@Author:zhoukaiyin
"""
def _read_data(input_file):
"""Read a BIO data!"""
rf = open(input_file, 'r')
lines = []; words = []; labels = []
for line in rf:
word = line.strip().split(' ')[0]
label = line.strip().split(' ')[-1]
# here we dont do "DOCSTART" check
if len(line.strip()) == 0 and words[-1] == '.':
l = ' '.join([label for label in labels if len(label) > 0])
w = ' '.join([word for word in words if len(word) > 0])
lines.append((l, w))
words = []
labels = []
words.append(word)
labels.append(label)
return lines
def main():
lines = _read_data("./data/train.txt")
print(lines)
main()
1
https://gitee.com/yasiping/BERT-NER.git
git@gitee.com:yasiping/BERT-NER.git
yasiping
BERT-NER
BERT-NER
master

搜索帮助