自然语言处理中的单词向量化

时间:2019-03-19 16:23:43

标签: python machine-learning natural-language-processing

我有一个数据集。该数据集仅包含单词。我必须对这些单词进行矢量化处理。我已经在寻找单词向量算法。单词袋word2wec,tf-idf单词袋word2wec,tf-idf正在对句子中的单词进行矢量化处理。但是我没有句子。我只有话。那么如何进行矢量引导呢?

1 个答案:

答案 0 :(得分:0)

Spacy 有一个用于获取 300 维的词向量的库。 您需要如代码中所示加载矢量包。 token.vector将为您提供一个单个单词的向量。

func buildImage(of size: CGSize) {
    DispatchQueue.global().async {
        var lastDrawn = CACurrentMediaTime()

        UIGraphicsBeginImageContextWithOptions(size, false, 0)

        for _ in 0 ..< 100_000 {
            self.someColor().setFill()
            UIBezierPath(rect: self.someRectangle(in: size)).fill()

            let now = CACurrentMediaTime()
            if now - lastDrawn > 0.25 {
                self.updateImageView()
                lastDrawn = now
            }
        }

        self.updateImageView()

        UIGraphicsEndImageContext()
    }
}

func updateImageView() {
    let image = UIGraphicsGetImageFromCurrentImageContext()
    DispatchQueue.main.async {
        self.imageView.image = image
    }
}

func someRectangle(in size: CGSize) -> CGRect {
    let x = CGFloat.random(in: 0...size.width)
    let y = CGFloat.random(in: 0...size.height)
    let width = CGFloat.random(in: 0...(size.width - x))
    let height = CGFloat.random(in: 0...(size.height - y))

    return CGRect(x: x, y: y, width: width, height: height)
}

func someColor() -> UIColor {
    return UIColor(red: .random(in: 0...1),
                   green: .random(in: 0...1),
                   blue: .random(in: 0...1),
                   alpha: 1)
}