How can I read a dictionary from file? for example my text file look like this:
[“book": [-0.33568978, -0.42831486],...]
and i want to read it and put in a dictionary
let myVector = [String:[Double]]()
How can I read a dictionary from file? for example my text file look like this:
[“book": [-0.33568978, -0.42831486],...]
and i want to read it and put in a dictionary
let myVector = [String:[Double]]()
Here is my solution for anyone else who try to import their own custom embedding with CreateML.
import Foundation
import PlaygroundSupport
import CreateML
do {
let fileUrl = PlaygroundSupport.playgroundSharedDataDirectory.appendingPathComponent("resultsmall.json")
let data = try Data(contentsOf: fileUrl)
let decoder = JSONDecoder()
let json = try decoder.decode([String: [Double]].self, from: data)
let embedding = try MLWordEmbedding(dictionary: json)
try embedding.write(to: URL(fileURLWithPath: "~/Desktop/WordEmbedding.mlmodel"))
} catch {
print(error)
}