2023-05-24 15:06:45 +00:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"# ModelScope\n",
|
|
|
|
"\n",
|
2023-09-08 02:53:33 +00:00
|
|
|
">[ModelScope](https://www.modelscope.cn/home) is big repository of the models and datasets.\n",
|
|
|
|
"\n",
|
2023-05-24 15:06:45 +00:00
|
|
|
"Let's load the ModelScope Embedding class."
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"from langchain.embeddings import ModelScopeEmbeddings"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"model_id = \"damo/nlp_corom_sentence-embedding_english-base\""
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"embeddings = ModelScopeEmbeddings(model_id=model_id)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"text = \"This is a test document.\""
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"query_result = embeddings.embed_query(text)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"doc_results = embeddings.embed_documents([\"foo\"])"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
2023-09-08 02:53:33 +00:00
|
|
|
"display_name": "Python 3 (ipykernel)",
|
2023-05-24 15:06:45 +00:00
|
|
|
"language": "python",
|
|
|
|
"name": "python3"
|
|
|
|
},
|
|
|
|
"language_info": {
|
2023-09-08 02:53:33 +00:00
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
2023-05-24 15:06:45 +00:00
|
|
|
"name": "python",
|
2023-09-08 02:53:33 +00:00
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
|
|
|
"version": "3.10.12"
|
|
|
|
}
|
2023-05-24 15:06:45 +00:00
|
|
|
},
|
|
|
|
"nbformat": 4,
|
2023-09-08 02:53:33 +00:00
|
|
|
"nbformat_minor": 4
|
2023-05-24 15:06:45 +00:00
|
|
|
}
|