文字的通用簽名

本頁面說明在 TF1 Hub 格式模組中,接受文字輸入的工作應實作的通用簽名。(如需 TF2 SavedModel 格式,請參閱類似的 SavedModel API。)

文字特徵向量

文字特徵向量模組會從文字特徵建立密集向量表示法。它接受形狀為 [batch_size] 的字串批次,並將其對應至形狀為 [batch_size, N]float32 張量。這通常稱為 N 維度的文字嵌入

基本用法

  embed = hub.Module("path/to/module")
  representations = embed([
      "A long sentence.",
      "single-word",
      "http://example.com"])

特徵欄用法

    feature_columns = [
      hub.text_embedding_column("comment", "path/to/module", trainable=False),
    ]
    input_fn = tf.estimator.inputs.numpy_input_fn(features, labels, shuffle=True)
    estimator = tf.estimator.DNNClassifier(hidden_units, feature_columns)
    estimator.train(input_fn, max_steps=100)

注意事項

模組已針對不同的網域和/或工作預先訓練,因此並非每個文字特徵向量模組都適用於您的問題。例如:有些模組可能只針對單一語言進行訓練。

此介面不允許在 TPU 上微調文字表示法,因為它要求模組同時例項化字串處理和可訓練變數。