Estrarre frasi chiave
L'estrazione di frasi chiave è una funzionalità offerta dal linguaggio di Azure. Identifica le frasi chiave, o concetti principali, nel testo.
Esistono diversi modi per chiamare l'API di estrazione di frasi chiave. In questo caso si usa l'estensione azure_ai per estrarre frasi chiave nelle query SQL.
Prerequisiti
È necessario un server flessibile di Database di Azure per PostgreSQL, con l'estensione azure_aiabilitata e configurata. È anche necessario autorizzarla con Servizi cognitivi di Azure impostando la chiave e l'endpoint di una risorsa di linguaggio.
Scenari
L'estrazione di frasi chiave si applica a varie attività:
- Riepilogo: usare frasi chiave per ridurre la lunghezza dei documenti agli argomenti principali, ad esempio l'identificazione di argomenti descritti nelle trascrizioni audio o nelle note delle riunioni.
- Categorizzazione del contenuto: usare frasi chiave per indicizzare i documenti per la ricerca e l'esplorazione. Le frasi chiave possono essere usate anche per visualizzare i documenti nelle nuvole di parole.
- Clustering di documenti: raccolte estese di ticket di supporto, recensioni dei prodotti e altri input non strutturati possono essere raggruppate e analizzate usando frasi chiave.
Uso di SQL per l'estrazione di frasi chiave con Servizi cognitivi di Azure
L'estensione azure_ai per il server flessibile di Database di Azure per PostgreSQL fornisce funzioni definite dall'utente (UDF) per accedere direttamente alle funzionalità di intelligenza artificiale dall'interno di SQL. L'API di estrazione di frasi chiave è accessibile con la azure_cognitive.extract_key_phrases funzione :
azure_cognitive.extract_key_phrases(
text TEXT,
language TEXT,
timeout_ms INTEGER DEFAULT 3600000,
throw_on_error BOOLEAN DEFAULT TRUE,
disable_service_logs BOOLEAN DEFAULT FALSE
)
I parametri obbligatori sono text, l'input e language, la lingua in cui viene scritto .text Ad esempio, en-us è inglese degli Stati Uniti e fr è francese. Per l'elenco completo delle lingue disponibili, vedere supporto per la lingua .
Per impostazione predefinita, l'estrazione di frasi chiave viene arrestata se non termina in 3.600.000 ms, ovvero 1 ora. È possibile personalizzare questo ritardo modificando timeout_ms.
Se si verifica un errore, il comportamento predefinito consiste nel generare un'eccezione, generando un rollback delle transazioni. È possibile disabilitare questo comportamento impostando su throw_on_error false.
Per la documentazione completa dei parametri, vedere la documentazione dell'estensione Servizi cognitivi di Azure .
Ad esempio, richiamare questa query:
SELECT azure_cognitive.extract_key_phrases('The food was delicious and the staff were wonderful.', 'en-us');
Restituisce questo risultato:
extract_key_phrases
---------------------
{food,staff}
È possibile usare colonne di tabella per il testo di input:
SELECT description, azure_cognitive.extract_key_phrases(description, 'en-us')
FROM listings LIMIT 1;
Che cosa restituisce (con \x attivato per la visualizzazione estesa):
description | Welcome! If you stay here you will be living in a light filled two bedroom upper and ground level apartment (in a two apartment home). During your stay you will be welcome to share in our fresh eggs from the chickens and garden produce in season! Welcome! Come enjoy your time in Seattle at a lovely urban farmstead. There are two bedrooms each with a queen bed, full bath, living room and kitchen with wood floors throughout. During your stay you will be welcome to eat fresh eggs from the chickens and possibly fruit/veggies from the garden if you are in luck! We are family friendly and have a down to earth atmosphere. There is a large covered back porch and grill for hanging out especially in summer and a treehouse for up in the trees hammock time! Walking distance to Othello Light Rail Station for easy access to downtown. Also nearby is the fantastic Seward Park and the Kubota Gardens for outdoorsy loveliness. New last year is out beautiful Rainier Beach indoor swimming pool comp
extract_key_phrases | {"beautiful Rainier Beach indoor swimming pool","large covered back porch","Othello Light Rail Station","ground level apartment","lovely urban farmstead","fantastic Seward Park","two bedroom upper","two apartment home","two bedrooms","fresh eggs","queen bed","full bath","living room","wood floors","earth atmosphere","Walking distance","easy access","Kubota Gardens","outdoorsy loveliness","garden produce","hammock time",stay,chickens,season,Seattle,kitchen,fruit/veggies,luck,grill,summer,treehouse,trees,downtown,last}
Riassunto
L'estrazione di frasi chiave seleziona i concetti principali dal testo. Il modello linguistico di Servizi cognitivi di Azure è responsabile dell'ebollizione del linguaggio naturale in parole chiave o frasi. L'estensione azure_ai per Database di Azure per PostgreSQL fornisce l'API azure_cognitive.extract_key_phrases per accedere all'estrazione di frasi chiave direttamente nelle query SQL.