<jupyter_start><jupyter_text>Extract feature vectors from text corpus using universal-sentence-encoder-multilingualAuthor: <NAME><jupyter_code>!pip3 install tensorflow_text>=2.0.0rc0
import tensorflow_hub as hub
import numpy as np
import tensorflow_text

import pandas as pd
import altair as alt

import seaborn as sns
import matplotlib.pyplot as plt
# The 16-language multilingual module is the default but feel free
# to pick others from the list and compare the results.
module_url = 'https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/3' #@param ['https://tfhub.dev/google/universal-sentence-encoder-multilingual/3', 'https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/3']

model = hub.load(module_url)
data = pd.read_csv("/content/export1305.csv")
titles = data["titel"].fillna("")
titles_embeds = model(titles)
titles_embeds
np.inner(titles_embeds, titles_embeds)
def arr_to_csv(arr, filename, mult=10000):
  dataframe = (pd.DataFrame(arr) * mult).round(0).astype('int32')
  dataframe['id'] = data['id']
  dataframe.to_csv(filename)
  return dataframe
dataframe = arr_to_csv(titles_embeds, "use.csv")
dataframe
import umap

def run_umap(data):
  umap_op = umap.UMAP(n_components=2)
  data_umap = umap_op.fit_transform(data)
  data_umap_df = pd.DataFrame(data=data_umap, columns=['x', 'y'])
  return data_umap_df
umap_title = run_umap(titles_embeds)
alt.data_transformers.disable_max_rows()
alt.Chart(pd.concat([titles,umap_title], axis=1)).encode(
      x='x',
      y='y',
      tooltip=['titel']
  ).mark_circle(size=60).properties(
      width=500, height=500
  ).interactive()<jupyter_output><empty_output>