@@ -12,7 +12,7 @@ Vocab::Vocab(StringList tokens, const std::optional<int64_t>& default_index)
1212 : stoi_(MAX_VOCAB_SIZE, -1 ), default_index_{default_index} {
1313 for (auto & token : tokens) {
1414 // throw error if duplicate token is found
15- auto id = _find (c10 ::string_view{token});
15+ auto id = _find (std ::string_view{token});
1616 TORCH_CHECK (
1717 stoi_[id] == -1 , " Duplicate token found in tokens list: " + token);
1818
@@ -26,15 +26,15 @@ int64_t Vocab::__len__() const {
2626 return itos_.size ();
2727}
2828
29- bool Vocab::__contains__ (const c10 ::string_view& token) const {
29+ bool Vocab::__contains__ (const std ::string_view& token) const {
3030 int64_t id = _find (token);
3131 if (stoi_[id] != -1 ) {
3232 return true ;
3333 }
3434 return false ;
3535}
3636
37- int64_t Vocab::__getitem__ (const c10 ::string_view& token) const {
37+ int64_t Vocab::__getitem__ (const std ::string_view& token) const {
3838 int64_t id = _find (token);
3939 if (stoi_[id] != -1 )
4040 return stoi_[id];
@@ -59,7 +59,7 @@ std::optional<int64_t> Vocab::get_default_index() const {
5959
6060void Vocab::append_token (std::string token) {
6161 // throw error if token already exist in vocab
62- auto id = _find (c10 ::string_view{token});
62+ auto id = _find (std ::string_view{token});
6363 TORCH_CHECK (
6464 stoi_[id] == -1 ,
6565 " Token " + token + " already exists in the Vocab with index: " +
@@ -80,10 +80,10 @@ void Vocab::insert_token(std::string token, const int64_t& index) {
8080
8181 // need to offset all tokens greater than or equal index by 1
8282 for (size_t i = index; i < __len__ (); i++) {
83- stoi_[_find (c10 ::string_view{itos_[i]})] = i + 1 ;
83+ stoi_[_find (std ::string_view{itos_[i]})] = i + 1 ;
8484 }
8585
86- stoi_[_find (c10 ::string_view{token})] = index;
86+ stoi_[_find (std ::string_view{token})] = index;
8787 itos_.insert (itos_.begin () + index, std::move (token));
8888}
8989
@@ -115,7 +115,7 @@ StringList Vocab::lookup_tokens(const std::vector<int64_t>& indices) {
115115}
116116
117117std::vector<int64_t > Vocab::lookup_indices (
118- const std::vector<c10 ::string_view>& tokens) {
118+ const std::vector<std ::string_view>& tokens) {
119119 std::vector<int64_t > indices (tokens.size ());
120120 for (size_t i = 0 ; i < tokens.size (); i++) {
121121 indices[i] = __getitem__ (tokens[i]);
@@ -127,7 +127,7 @@ std::unordered_map<std::string, int64_t> Vocab::get_stoi() const {
127127 std::unordered_map<std::string, int64_t > stoi;
128128 // construct tokens and index list
129129 for (const auto & item : itos_) {
130- stoi[item] = __getitem__ (c10 ::string_view{item});
130+ stoi[item] = __getitem__ (std ::string_view{item});
131131 }
132132 return stoi;
133133}
0 commit comments