2

Form Recognizer Studio has an option to share and import custom created models. It generates a token for the model which can be shared and imported into another account.

I wanted to get this token using Python for a script. Is there any way I can do this task in Python? Thank You!

I tried using the below code

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import FormTrainingClient

client = FormTrainingClient(endpoint, AzureKeyCredential(key))

target = client.get_copy_authorization(resource_id="", resource_region="eastus")

Using this code, I can get the accessToken, but this is associated to Resource Group. I wanted to get token to share Custom built Form Recognizer Model.

1 Answers1

0

According to the solution in this github issue, Refer here:- TypeError: in method 'IndexFlat_add', argument 3 of type 'float const *' · Issue #461 · facebookresearch/faiss · GitHub Make sure the generated vector types or array is of numpy.float32

Code 1:-

import numpy as np
d = 128
n = 10000
xb = np.random.rand(n, d).astype(np.float32)

vector = [0.5] * d
vector = np.array(vector).astype(np.float32)

distances = np.linalg.norm(xb - vector, axis=1)

k = 5
indices = np.argsort(distances)[:k]

print("Distances:", distances[indices])
print("Indices:", indices)

Above code with faiss library.

import numpy as np
import faiss

d = 128
n = 10000
index = faiss.IndexFlatL2(d)
xb = np.random.rand(n, d).astype(np.float32)

index.add(xb)

vector = [0.5] * d
vector = np.array(vector).astype(np.float32)
k = 5
distances, indices = index.search(np.array([vector]), k)

print("Distances:", distances)
print("Indices:", indices)

Output:-

enter image description here

Code 2:-

import numpy as np

d = 128

n = 10000

x = np.random.rand(n, d).astype(np.float32)

print (x)

Output:-

enter image description here

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11
  • Thanks a lot dude for your generous help. I have tried using this method, it copies the custom model into different Azure account but, it does not allow second user to access and edit the labels of data. That's why I needed the generated token to import the project. Please let me know if there is any other way this can be done in Python. – Rahul Borole Apr 18 '23 at 16:21