File tree 1 file changed +15
-2
lines changed
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 6
6
// Copyright © 2024 Hugging Face. All rights reserved.
7
7
//
8
8
9
+ import Foundation
9
10
import Hub
10
11
11
12
class UnigramTokenizer : PreTrainedTokenizerModel {
@@ -37,8 +38,20 @@ class UnigramTokenizer: PreTrainedTokenizerModel {
37
38
}
38
39
39
40
vocab = try configVocab. map { piece in
40
- guard let token = piece. first as? String else { throw TokenizerError . malformedVocab }
41
- guard let score = piece. last as? Float else { throw TokenizerError . malformedVocab }
41
+ guard let token = piece. first as? String ,
42
+ let scoreValue = piece. last else {
43
+ throw TokenizerError . malformedVocab
44
+ }
45
+
46
+ let score : Float
47
+ if let floatScore = scoreValue as? Float {
48
+ score = floatScore
49
+ } else if let numberScore = scoreValue as? NSNumber {
50
+ score = numberScore. floatValue
51
+ } else {
52
+ throw TokenizerError . malformedVocab
53
+ }
54
+
42
55
return SentencePieceToken ( token: token, score: score)
43
56
}
44
57
You can’t perform that action at this time.
0 commit comments