dsindex / syntaxnet

reference code for syntaxnet
197 stars 57 forks source link

How to train Chinese tokenizer using Syntaxnet? #15

Closed i-xying closed 7 years ago

i-xying commented 7 years ago

Hi , I have trained my Chinese model refering to how to train English model. But how can I make Chinese tokenizer? When I test my Chinese model with MODEL_DIRECTORY=/xy/models/syntaxnet/Chinesemodel echo '這樣的處理也衍生了一些問題.' | ./parse.sh The result is just all the sentence as a noun.

dsindex commented 7 years ago

what about using parsey's cousins?

https://github.com/tensorflow/models/blob/master/syntaxnet/universal.md

 MODEL_DIRECTORY=/where/you/unzipped/the/model/files
  cat sentences.txt | syntaxnet/models/parsey_universal/tokenize_zh.sh \
    $MODEL_DIRECTORY > output.conll

you can preprocess input sentences and feed to ./parse.sh

beside using the pre-trained segmentation model for Chinese, there is no officially known method to train a segmentation model using the Syntaxnet.

however, i guess some tricks.

=>

1 프 프 NNP NNP 2 2 랑 랑 NNP NNP 3 3 스 스 NNP NNP 4 4 의 의 JKG JKG 12 5 세 세 NNG NNG 6 6 계 계 NNG NNG 7 7 적 적 XSN XSN 8 8 이 이 VCP VCP 9 9 ᆫ ᆫ ETM ETM 12 10 의 의 NNG NNG 11 11 상 상 NNG NNG 12 12 디 디 NNG NNG 13 13 자 자 NNG NNG 14 14 이 이 NNG NNG 15 15 너 너 NNG NNG 20 16 엠 엠 NNP NNP 17 17 마 마 NNP NNP 18 18 누 누 NNP NNP 19 19 엘 엘 NNP NNP 20 20 웅 웅 NNP NNP 21 21 가 가 NNP NNP 22 22 로 로 NNP NNP 23 23 가 가 JKS JKS 36 24 실 실 NNG NNG 25 25 내 내 NNG NNG 26 26 장 장 NNG NNG 27 27 식 식 NNG NNG 28 28 용 용 XSN XSN 29 29 직 직 NNG NNG 30 30 물 물 NNG NNG 31 31 디 디 NNG NNG 32 32 자 자 NNG NNG 33 33 이 이 NNG NNG 34 34 너 너 NNG NNG 35 35 로 로 JKB JKB 36 36 나 나 VV VV 37 37 서 서 VV VV 38 38 었 었 EP EP 39 39 다 다 EF EF 40 40 . . SF SF 0


basically we want to segment input string to meaningful words. 
it seems that above data is not proper to segmentation. 

- set governor's index using word boundary itself.

1 프 프 NNP NNP 2 2 랑 랑 NNP NNP 3 3 스 스 NNP NNP 4 4 의 의 JKG JKG 40 5 세 세 NNG NNG 6 6 계 계 NNG NNG 7 7 적 적 XSN XSN 8 8 이 이 VCP VCP 9 9 ᆫ ᆫ ETM ETM 40 10 의 의 NNG NNG 11 11 상 상 NNG NNG 40 12 디 디 NNG NNG 13 13 자 자 NNG NNG 14 14 이 이 NNG NNG 15 15 너 너 NNG NNG 40 16 엠 엠 NNP NNP 17 17 마 마 NNP NNP 18 18 누 누 NNP NNP 19 19 엘 엘 NNP NNP 40 20 웅 웅 NNP NNP 21 21 가 가 NNP NNP 22 22 로 로 NNP NNP 23 23 가 가 JKS JKS 40 24 실 실 NNG NNG 25 25 내 내 NNG NNG 40 26 장 장 NNG NNG 27 27 식 식 NNG NNG 28 28 용 용 XSN XSN 40 29 직 직 NNG NNG 30 30 물 물 NNG NNG 40 31 디 디 NNG NNG 32 32 자 자 NNG NNG 33 33 이 이 NNG NNG 34 34 너 너 NNG NNG 35 35 로 로 JKB JKB 40 36 나 나 VV VV 37 37 서 서 VV VV 38 38 었 었 EP EP 39 39 다 다 EF EF 40 40 . . SF SF 0


here every boundary characters are governed by the last character.
and notice that we can't use the part-of-speech tag.(just ignore those fields)

if we get a model trained by this data, we can segment input sentence by identifying governor's index. 

insert space if governor's index is last one do not insert space otherwise



does it seems to make sense? 
i-xying commented 7 years ago

@dsindex Thank you very much ! I have used the parsey's cousin as you mentioned above . When I use the Chinese (download from the official website of TensorFlow) It can successfully segment sentences and give true POS and Parsey. But when I train my own Chinesemodel using the datasets UD_Chinese (Following your method in https://github.com/dsindex/syntaxnet), It can not generate the tokenizer. The contrast of Chinese and Chinesemodel is as follows. Chinese: image

Chinesemodel: image When I train my own model , I used your giving bash--train.sh, and the context.pbtxt copying from the UD_English. I think I should transform the bash and the context.pbtxt , but I have no ideas about it. Is there any better suggestions? your giving suggestion I think it may very helpful when I create my own corpus, Thanks a lot.

dsindex commented 7 years ago

@i-xying unfortunately 'train.sh' only generates pos and parse model for an UD corpus. i think Google Brain Team will announce how to train a segmentation model in the future.

i-xying commented 7 years ago

@dsindex OK! I know. Thank you. I think I should try to learn how to transform the bash.