@@ -12,7 +12,7 @@ Vocab::Vocab(StringList tokens, const std::optional<int64_t>& default_index)
12
12
: stoi_(MAX_VOCAB_SIZE, -1 ), default_index_{default_index} {
13
13
for (auto & token : tokens) {
14
14
// throw error if duplicate token is found
15
- auto id = _find (c10 ::string_view{token});
15
+ auto id = _find (std ::string_view{token});
16
16
TORCH_CHECK (
17
17
stoi_[id] == -1 , " Duplicate token found in tokens list: " + token);
18
18
@@ -26,15 +26,15 @@ int64_t Vocab::__len__() const {
26
26
return itos_.size ();
27
27
}
28
28
29
- bool Vocab::__contains__ (const c10 ::string_view& token) const {
29
+ bool Vocab::__contains__ (const std ::string_view& token) const {
30
30
int64_t id = _find (token);
31
31
if (stoi_[id] != -1 ) {
32
32
return true ;
33
33
}
34
34
return false ;
35
35
}
36
36
37
- int64_t Vocab::__getitem__ (const c10 ::string_view& token) const {
37
+ int64_t Vocab::__getitem__ (const std ::string_view& token) const {
38
38
int64_t id = _find (token);
39
39
if (stoi_[id] != -1 )
40
40
return stoi_[id];
@@ -59,7 +59,7 @@ std::optional<int64_t> Vocab::get_default_index() const {
59
59
60
60
void Vocab::append_token (std::string token) {
61
61
// throw error if token already exist in vocab
62
- auto id = _find (c10 ::string_view{token});
62
+ auto id = _find (std ::string_view{token});
63
63
TORCH_CHECK (
64
64
stoi_[id] == -1 ,
65
65
" Token " + token + " already exists in the Vocab with index: " +
@@ -80,10 +80,10 @@ void Vocab::insert_token(std::string token, const int64_t& index) {
80
80
81
81
// need to offset all tokens greater than or equal index by 1
82
82
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 ;
84
84
}
85
85
86
- stoi_[_find (c10 ::string_view{token})] = index;
86
+ stoi_[_find (std ::string_view{token})] = index;
87
87
itos_.insert (itos_.begin () + index, std::move (token));
88
88
}
89
89
@@ -115,7 +115,7 @@ StringList Vocab::lookup_tokens(const std::vector<int64_t>& indices) {
115
115
}
116
116
117
117
std::vector<int64_t > Vocab::lookup_indices (
118
- const std::vector<c10 ::string_view>& tokens) {
118
+ const std::vector<std ::string_view>& tokens) {
119
119
std::vector<int64_t > indices (tokens.size ());
120
120
for (size_t i = 0 ; i < tokens.size (); i++) {
121
121
indices[i] = __getitem__ (tokens[i]);
@@ -127,7 +127,7 @@ std::unordered_map<std::string, int64_t> Vocab::get_stoi() const {
127
127
std::unordered_map<std::string, int64_t > stoi;
128
128
// construct tokens and index list
129
129
for (const auto & item : itos_) {
130
- stoi[item] = __getitem__ (c10 ::string_view{item});
130
+ stoi[item] = __getitem__ (std ::string_view{item});
131
131
}
132
132
return stoi;
133
133
}
0 commit comments