Skip to content

Commit c78ec28

Browse files
committed
Match token value with array and tuple
* Add match cases for token value * Add BartTokenizer to known tokenizers
1 parent 1d26ce0 commit c78ec28

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Sources/Hub/Hub.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ public struct Config {
100100
}
101101

102102
/// Tuple of token identifier and string value
103-
public var tokenValue: (UInt, String)? { value as? (UInt, String) }
103+
public var tokenValue: (UInt, String)? {
104+
switch value {
105+
case let (i, t) as (UInt, String): return (i, t)
106+
case let (t, i) as (String, UInt): return (i, t)
107+
case let a as [Any] where a.count == 2: return (a[1], a[0]) as? (UInt, String)
108+
default: return nil
109+
}
110+
}
104111
}
105112

106113
public class LanguageModelConfigurationFromHub {

Sources/Tokenizers/Tokenizer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public protocol PreTrainedTokenizerModel: TokenizingModel {
7777

7878
struct TokenizerModel {
7979
static let knownTokenizers: [String : PreTrainedTokenizerModel.Type] = [
80+
"BartTokenizer" : BertTokenizer.self,
8081
"BertTokenizer" : BertTokenizer.self,
8182
"DistilbertTokenizer": BertTokenizer.self,
8283
"DistilBertTokenizer": BertTokenizer.self,

0 commit comments

Comments
 (0)