The issue I met when do the NER task for Universal language by using XLM-R
Author: zongbingwang
Pull request: no
Labels: name: wontfix

# ❓ Questions & Help

<!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. Make sure to tag your question with the
     right deep learning framework as well as the huggingface-transformers tag: 
     https://stackoverflow.com/questions/tagged/huggingface-transformers 
     
     If your question wasn't answered after a period of time on Stack Overflow, you
     can always open a question on GitHub. You should then link to the SO question 
     that you posted.
     -->

## Details
<!-- Description of your issue -->

<!-- You should first ask your question on SO, and only if
     you didn't get an answer ask it here on GitHub. -->


**A link to original question on Stack Overflow**: 
Firstly, go through the roughly logic when we do slot tagging task for English query, take query “what’s the weather in Beijing” and detect location slot tagging as example:
1. We are using space to split the query and label it as “O O O O B-location” when generate the training data
2. By using sentence piece to tokenize the query to ['_what', "'", 's', '_the', '_weather', '_in', '_bei', 'jing'], and corresponding tagging mask [1, 0, 0, 1, 1, 1, 1, 0] (take first token in the word as 1, other tokens in the word as 0)
3. By using NER task to do the predict, and then extract the token’s prediction result as the word prediction result if the token’s mask is 1
 
When we do the NER task as above logic for CJK language, take “今天北京天气怎么样？” as example, after sentence piece tokenize, the tokens is ['▁', '北京', '今天', '天气', '怎么样', '?'], since there are no space in the query, so it will take the whole query as one slot and the corresponding tagging mask is [1, 0, 0, 0, 0, 0], so we can’t get the location slot “北京”
 
The cause is that the split methods for English and CJK are different, In French, “Je t’aime” is means “I love you”, “Je” means “I”, “t’” means “you”, “aime” means “love”, it is using “’” as splitter.

I think we can solve it by using below solutions:
1. Detect what language it is firstly for the query
2. For the language likes English, we don’t change the logic as above, for the language likes CJK, after split by using space, we can use tokens generated by sentence piece as word,
a. For example “北京今天天气怎么样，西雅图呢?”, split it as [“北京今天天气怎么样”, “西雅图呢?”] as space
b. For “北京今天天气怎么样”,  after tokenized is: ['▁', '北京', '今天', '天气', '怎么样', ',’], we mark each token as word we need to predict, the correspond tagging mask is [0, 1, 1, 1, 1, 0]
By using NER task to do the predict, and then extract the token’s prediction result as the word prediction result if the token’s mask is 1, so we can predict ‘北京’ as location slot

But for this, it needs to have specific language knowledge and language classification detector, any better ideas do you have?

Comments:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.