Comments (11)
Let's take '胖' as an example.
胖 胖肉半肉 月 肉 肉半
The third column is the simplified semantic radical, whereas the fourth column is the traditional form. The last column is the combination of traditional semantic radical and other components. They are not used in this paper.
from sub-character-cws.
Gotcha, thanks.
from sub-character-cws.
what does the radical.ngram.vec and radical.vec mean?
from sub-character-cws.
How to pre-train character embedding and radical embeddings jointly using fastText?Thank you!
from sub-character-cws.
radical.vec is actually the vector of a character in the form of its radical list.
radical.ngram.vec is the vector of each radical.
For joint pre-training, you need to
- Modify the source code of fastText, see attached patch.
- Convert your corpus to a sequence of characters in the form of their radical lists.
- Set
-minn 1 -maxn 1
, so every individual radical vector will be outputted, no more no less.
Index: src/fasttext.cc
<+>UTF-8
===================================================================
--- src/fasttext.cc (date 1500458693000)
+++ src/fasttext.cc (date 1526813653000)
@@ -50,7 +50,48 @@
ofs << word << " " << vec << std::endl;
}
ofs.close();
+
+ saveNgramVectors();
}
+
+ void FastText::saveNgramVectors() {
+ std::ofstream ofs(args_->output + ".ngram.vec");
+ if (!ofs.is_open()) {
+ std::cerr << "Error opening file for saving vectors." << std::endl;
+ exit(EXIT_FAILURE);
+ }
+
+ std::unordered_map<std::string, Vector> w2v; // collect all word, subword
+ for (int32_t i = 0; i < dict_->nwords(); i++) {
+ std::string word = dict_->getWord(i);
+ std::vector<int32_t> ngrams;
+ std::vector<std::string> substrings;
+ Vector vec(args_->dim);
+ dict_->getSubwords(word, ngrams, substrings);
+ for (int32_t i = 1; i < ngrams.size(); i++) { // skip the word its self
+ vec.zero(); // reuse memory
+ if (ngrams[i] >= 0) {
+ vec.addRow(*input_, ngrams[i]);
+ }
+// w2v[substrings[i]] = vec;
+ auto entry = w2v.emplace(::std::piecewise_construct // special to enable forwarding
+ , ::std::forward_as_tuple(substrings[i]) // arguments for key constructor
+ , ::std::forward_as_tuple(vec.size()) // arguments for value constructor
+ );
+ if (entry.second)
+ {
+ entry.first->second.zero();
+ entry.first->second.addVector(vec);
+ }
+ }
+ }
+ ofs << w2v.size() << " " << args_->dim << std::endl;
+ for(const auto &p : w2v)
+ {
+ ofs << p.first << " " << p.second << std::endl;
+ }
+ ofs.close();
+ }
void FastText::saveOutput() {
std::ofstream ofs(args_->output + ".output");
Index: src/fasttext.h
<+>UTF-8
===================================================================
--- src/fasttext.h (date 1500458693000)
+++ src/fasttext.h (date 1526813653000)
@@ -89,6 +89,8 @@
void loadVectors(std::string);
int getDimension() const;
+
+ void saveNgramVectors();
};
}
from sub-character-cws.
Thank you very much!
from sub-character-cws.
Is radical.ngram.vec the vector of each radical,not character?
from sub-character-cws.
Yes, radical embedding. Unigram inside character is radical.
from sub-character-cws.
get,thanks! I have one more question.For example,the 㐥 in radical.txt not in character.vec and character-bi.vec .Isn't character.vec the vector of each character?What does the character-bi.vec and character.vec mean?
from sub-character-cws.
radical.txt is a voluminous dictionary. What exists in a dictionary doesn't necessarily to appear in your text.
character.vec is embedding of char pre-trained without subword information (i.e. word2vec).
character-bi.vec is never used. I shouldn't have uploaded it. Now it's been removed.
from sub-character-cws.
hello, do you know 'python3 model.py --dataset dataset/$1-character/dataset.pkl'
where is the 'dataset'
from sub-character-cws.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sub-character-cws.