Upload sd_token_similarity_calculator.ipynb
Browse files
Google Colab Notebooks/sd_token_similarity_calculator.ipynb
CHANGED
@@ -2882,10 +2882,10 @@
|
|
2882 |
],
|
2883 |
"metadata": {
|
2884 |
"id": "rUXQ73IbonHY",
|
2885 |
-
"outputId": "0be95ebc-c6b0-4141-d299-d1e33c7a2e00",
|
2886 |
"colab": {
|
2887 |
"base_uri": "https://localhost:8080/"
|
2888 |
-
}
|
|
|
2889 |
},
|
2890 |
"execution_count": 1,
|
2891 |
"outputs": [
|
@@ -3033,10 +3033,10 @@
|
|
3033 |
],
|
3034 |
"metadata": {
|
3035 |
"id": "ZMG4CThUAmwW",
|
3036 |
-
"outputId": "d5ec8719-a0d7-4bff-f87c-379fed3a5d20",
|
3037 |
"colab": {
|
3038 |
"base_uri": "https://localhost:8080/"
|
3039 |
-
}
|
|
|
3040 |
},
|
3041 |
"execution_count": 2,
|
3042 |
"outputs": [
|
@@ -3857,18 +3857,17 @@
|
|
3857 |
" text_features = text_encodings[f'{index}']\n",
|
3858 |
"\n",
|
3859 |
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
3860 |
-
" sims[index] = torch.
|
3861 |
" if name_NEG != '':\n",
|
3862 |
" torch.matmul(text_features_NEG, image_features.t()) * logit_scale\n",
|
3863 |
-
" sims[index] = sims[index] - neg_strength* torch.
|
3864 |
" if image_NEG != '':\n",
|
3865 |
-
" sims[index] = sims[index] - neg_strength* torch.
|
3866 |
"#-------#\n",
|
3867 |
"sorted , indices = torch.sort(sims,dim=0 , descending=True)"
|
3868 |
],
|
3869 |
"metadata": {
|
3870 |
"id": "rebogpoyOG8k",
|
3871 |
-
"outputId": "c2a9083b-3b49-4693-bb17-4b829182462f",
|
3872 |
"colab": {
|
3873 |
"base_uri": "https://localhost:8080/",
|
3874 |
"height": 273,
|
@@ -3962,7 +3961,8 @@
|
|
3962 |
"9b8be4e7d91a47c2852ca202528744cf",
|
3963 |
"78b25863b7cc4400abf53a04e1f67bb2"
|
3964 |
]
|
3965 |
-
}
|
|
|
3966 |
},
|
3967 |
"execution_count": 4,
|
3968 |
"outputs": [
|
@@ -4127,10 +4127,10 @@
|
|
4127 |
],
|
4128 |
"metadata": {
|
4129 |
"id": "JkzncP8SgKtS",
|
4130 |
-
"outputId": "d47b9b06-982a-457e-ef50-60664ba6c11f",
|
4131 |
"colab": {
|
4132 |
"base_uri": "https://localhost:8080/"
|
4133 |
-
}
|
|
|
4134 |
},
|
4135 |
"execution_count": 6,
|
4136 |
"outputs": [
|
|
|
2882 |
],
|
2883 |
"metadata": {
|
2884 |
"id": "rUXQ73IbonHY",
|
|
|
2885 |
"colab": {
|
2886 |
"base_uri": "https://localhost:8080/"
|
2887 |
+
},
|
2888 |
+
"outputId": "0be95ebc-c6b0-4141-d299-d1e33c7a2e00"
|
2889 |
},
|
2890 |
"execution_count": 1,
|
2891 |
"outputs": [
|
|
|
3033 |
],
|
3034 |
"metadata": {
|
3035 |
"id": "ZMG4CThUAmwW",
|
|
|
3036 |
"colab": {
|
3037 |
"base_uri": "https://localhost:8080/"
|
3038 |
+
},
|
3039 |
+
"outputId": "d5ec8719-a0d7-4bff-f87c-379fed3a5d20"
|
3040 |
},
|
3041 |
"execution_count": 2,
|
3042 |
"outputs": [
|
|
|
3857 |
" text_features = text_encodings[f'{index}']\n",
|
3858 |
"\n",
|
3859 |
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
3860 |
+
" sims[index] = torch.nn.functional.cosine_similarity(text_features, image_features)\n",
|
3861 |
" if name_NEG != '':\n",
|
3862 |
" torch.matmul(text_features_NEG, image_features.t()) * logit_scale\n",
|
3863 |
+
" sims[index] = sims[index] - neg_strength* torch.nn.functional.cosine_similarity(text_features_NEG, image_features)\n",
|
3864 |
" if image_NEG != '':\n",
|
3865 |
+
" sims[index] = sims[index] - neg_strength* torch.nn.functional.cosine_similarity(image_features, image_features_NEG)\n",
|
3866 |
"#-------#\n",
|
3867 |
"sorted , indices = torch.sort(sims,dim=0 , descending=True)"
|
3868 |
],
|
3869 |
"metadata": {
|
3870 |
"id": "rebogpoyOG8k",
|
|
|
3871 |
"colab": {
|
3872 |
"base_uri": "https://localhost:8080/",
|
3873 |
"height": 273,
|
|
|
3961 |
"9b8be4e7d91a47c2852ca202528744cf",
|
3962 |
"78b25863b7cc4400abf53a04e1f67bb2"
|
3963 |
]
|
3964 |
+
},
|
3965 |
+
"outputId": "c2a9083b-3b49-4693-bb17-4b829182462f"
|
3966 |
},
|
3967 |
"execution_count": 4,
|
3968 |
"outputs": [
|
|
|
4127 |
],
|
4128 |
"metadata": {
|
4129 |
"id": "JkzncP8SgKtS",
|
|
|
4130 |
"colab": {
|
4131 |
"base_uri": "https://localhost:8080/"
|
4132 |
+
},
|
4133 |
+
"outputId": "d47b9b06-982a-457e-ef50-60664ba6c11f"
|
4134 |
},
|
4135 |
"execution_count": 6,
|
4136 |
"outputs": [
|