중지
stop 필터는 토큰화된 텍스트에서 지정된 스톱워드를 제거하여, 흔하지만 의미가 적은 단어들을 걸러내는 데 도움을 줍니다. stop_words 매개변수를 사용하여 스톱워드 목록을 구성할 수 있습니다.
구성
stop 필터는 stop_words 매개변수를 통해 인라인으로, 또는 stop_words_file 매개변수를 통해 등록된 파일 리소스에서 스톱워드 목록을 받아들입니다.
인라인 스톱워드 목록
인라인 목록과 함께 stop 필터를 사용하려면, 필터 구성에서 "type": "stop" 을 지정하고, 스톱워드 목록을 제공하는 stop_words 매개변수를 함께 지정하십시오.
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stop", # Specifies the filter type as stop
"stop_words": ["of", "to", "_english_"], # Defines custom stop words and includes the English stop word list
}],
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Collections.singletonList(
new HashMap<String, Object>() {{
put("type", "stop");
put("stop_words", Arrays.asList("of", "to", "_english_"));
}}
)
);
const analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stop", # Specifies the filter type as stop
"stop_words": ["of", "to", "_english_"], # Defines custom stop words and includes the English stop word list
}],
};
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "stop",
"stop_words": []string{"of", "to", "_english_"},
}}}
# restful
analyzerParams='{
"tokenizer": "standard",
"filter": [
{
"type": "stop",
"stop_words": [
"of",
"to",
"_english_"
]
}
]
}'
stop 필터는 다음과 같은 구성 가능한 매개변수를 지원합니다.
매개변수 |
설명 |
|---|---|
|
토큰화 과정에서 제외할 단어 목록입니다. 기본적으로 필터는 내장된
|
stop 필터는 토큰화기가 생성한 용어를 대상으로 작동하므로, 반드시 토큰화기와 함께 사용해야 합니다. Milvus에서 사용할 수 있는 토큰화기 목록은 표준 토큰화기 및 관련 페이지를 참조하십시오.
analyzer_params 를 정의한 후에는 컬렉션 스키마를 정의할 때 ‘ VARCHAR ’ 필드에 이를 적용할 수 있습니다. 이를 통해 Milvus는 해당 필드의 텍스트를 지정된 분석기를 사용하여 처리함으로써 효율적인 토큰화 및 필터링을 수행할 수 있습니다. 자세한 내용은 사용 예제를 참조하십시오.
파일 리소스에서 스톱워드 불러오기Compatible with Milvus 3.0.x
대규모 사용자 정의 스톱워드 목록(언어별 목록, 도메인 어휘집 또는 여러 컬렉션에서 공유하려는 목록 등)의 경우, 단어를 파일에 저장하고 해당 파일을 원격 파일 리소스로 등록한 다음, stop_words_file 매개변수를 통해 필터에서 이를 참조하십시오. stop_words_file 는 단독으로 사용하거나 인라인 stop_words 와 함께 사용할 수 있습니다. 두 가지가 모두 설정된 경우, 필터는 두 소스를 하나의 스톱워드 목록으로 병합합니다.
파일은 한 줄에 하나의 스톱워드가 포함된 일반 UTF‑8 텍스트 형식이어야 합니다. 예:
the
of
for
파일을 Milvus 클러스터가 사용하도록 구성된 오브젝트 스토어에 업로드한 다음, 등록하십시오:
from pymilvus import MilvusClient
client = MilvusClient(uri="http://localhost:19530")
# Register the uploaded file under a name you'll reference from analyzer configs.
client.add_file_resource(
name="en_stop_words",
path="file/stop_words.txt", # full S3 object key, including the rootPath prefix
)
stop_words_file 를 통해 필터에서 등록된 리소스를 참조하십시오:
analyzer_params = {
"tokenizer": "standard",
"filter": [{
"type": "stop",
"stop_words_file": {
"type": "remote",
"resource_name": "en_stop_words",
"file_name": "stop_words.txt",
},
}],
}
stop_words_file 매개변수는 다음 필드를 가진 객체를 허용합니다:
필드 |
설명 |
|---|---|
|
리소스 유형입니다. |
|
|
|
등록된 리소스의 오브젝트 스토어 경로 중 파일 이름 부분(예: 리소스가 |
예
분석기 구성을 컬렉션 스키마에 적용하기 전에 run_analyzer 메서드를 사용하여 동작을 확인하십시오.
분석기 구성
analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stop", # Specifies the filter type as stop
"stop_words": ["of", "to", "_english_"], # Defines custom stop words and includes the English stop word list
}],
}
Map<String, Object> analyzerParams = new HashMap<>();
analyzerParams.put("tokenizer", "standard");
analyzerParams.put("filter",
Collections.singletonList(
new HashMap<String, Object>() {{
put("type", "stop");
put("stop_words", Arrays.asList("of", "to", "_english_"));
}}
)
);
// javascript
analyzerParams = map[string]any{"tokenizer": "standard",
"filter": []any{map[string]any{
"type": "stop",
"stop_words": []string{"of", "to", "_english_"},
}}}
# restful
다음 도구를 사용한 검증 run_analyzer
from pymilvus import (
MilvusClient,
)
client = MilvusClient(uri="http://localhost:19530")
# Sample text to analyze
sample_text = "The stop filter allows control over common stop words for text processing."
# Run the standard analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("Standard analyzer output:", result)
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.vector.request.RunAnalyzerReq;
import io.milvus.v2.service.vector.response.RunAnalyzerResp;
ConnectConfig config = ConnectConfig.builder()
.uri("http://localhost:19530")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
List<String> texts = new ArrayList<>();
texts.add("The stop filter allows control over common stop words for text processing.");
RunAnalyzerResp resp = client.runAnalyzer(RunAnalyzerReq.builder()
.texts(texts)
.analyzerParams(analyzerParams)
.build());
List<RunAnalyzerResp.AnalyzerResult> results = resp.getResults();
// javascript
import (
"context"
"encoding/json"
"fmt"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
client, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: "localhost:19530",
APIKey: "root:Milvus",
})
if err != nil {
fmt.Println(err.Error())
// handle error
}
bs, _ := json.Marshal(analyzerParams)
texts := []string{"The stop filter allows control over common stop words for text processing."}
option := milvusclient.NewRunAnalyzerOption(texts).
WithAnalyzerParams(string(bs))
result, err := client.RunAnalyzer(ctx, option)
if err != nil {
fmt.Println(err.Error())
// handle error
}
# restful
예상 출력
['The', 'stop', 'filter', 'allows', 'control', 'over', 'common', 'stop', 'words', 'text', 'processing']