

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 自訂實體辨識器指標
<a name="cer-metrics"></a>

Amazon Comprehend 為您提供指標，協助您估計實體辨識器對您的任務應運作的程度。它們是以訓練辨識器模型為基礎，因此，雖然它們在訓練期間準確代表模型的效能，但它們只是實體探索期間 API 效能的近似值。

每當從訓練過的實體辨識器傳回中繼資料時，都會傳回指標。

Amazon Comprehend 支援一次在最多 25 個實體上訓練模型。從訓練過的實體辨識器傳回指標時，會針對辨識器整體 （全域指標） 和每個個別實體 （實體指標） 來計算分數。

有三種指標可用，包括全域和實體指標：
+ **精確度**

  這表示系統產生且正確識別和標記的實體部分。這會顯示模型的實體識別真正是良好識別的次數。這是識別總數的百分比。

  換言之，精確度是以*真陽性 (tp)* 和*偽陽性 (fp) *為基礎，並以*精確度 = tp / (tp \$1 fp)* 計算。

  例如，如果模型預測一個實體的兩個範例存在於文件中，其中實際上只有一個，則結果為一個真陽性和一個偽陽性。在此情況下，*精確度 = 1 / (1 \$1 1)*。精確度為 50%，因為模型識別的兩個實體中有一個是正確的。

  
+  **召回**

  這表示系統正確識別和標記文件中存在的實體部分。數學上，這是根據正確識別*真陽性 (tp)* 和遺漏識別*偽陰性 (fn) *的總數來定義。

   其計算方式為*取回 = tp / (tp \$1 fn)*。例如，如果模型正確識別一個實體，但遺漏了該實體存在的兩個其他執行個體，則結果為一個真陽性和兩個假陰性。在這種情況下，*召回 = 1 / (1 \$1 2)*。召回率為 33.33%，因為在可能的三個範例中，有一個實體是正確的。

  
+ **F1 分數** 

  這是精確度和召回指標的組合，可測量模型的整體準確性以進行自訂實體辨識。F1 分數是精確度和召回指標的調和平均值：*F1 = 2 \$1 精確度 \$1 召回 / （精確度 \$1 召回）。 *
**注意**  
直覺上，與簡單平均值或其他方法相比，調和平均值會懲罰極端值 （例如： `precision` = 0， `recall` = 1 可以透過預測所有可能的跨度來微乎其微地實現。 在這裡，簡單平均值為 0.5，但`F1`會懲罰為 0)。

  在上述範例中， `precision` = 50% 且 `recall` = 33.33%，因此 `F1` = 2 \$1 0.5 \$1 0.3333 / (0.5 \$1 0.3333)。F1 分數為 .3975 或 39.75%。

  

**全域和個別實體指標**

分析某個*地方*或*個人*實體的下列句子時，可以看到全域和個別實體指標之間的關係

```
John Washington and his friend Smith live in San Francisco, work in San Diego, and own 
    a house in Seattle.
```

在我們的範例中，模型會進行下列預測。

```
John Washington = Person
Smith = Place
San Francisco = Place
San Diego = Place
Seattle = Person
```

不過，預測應該如下。

```
John Washington = Person
Smith = Person  
San Francisco = Place
San Diego = Place
Seattle = Place
```

此項目的個別實體指標為：

```
entity:  Person
  True positive (TP) = 1 (because John Washington is correctly predicted to be a 
    Person).
  False positive (FP) = 1 (because Seattle is incorrectly predicted to be a Person, 
    but is actually a Place).
  False negative (FN) = 1 (because Smith is incorrectly predicted to be a Place, but 
    is actually a Person).
  Precision = 1 / (1 + 1) = 0.5 or 50%
  Recall = 1 / (1+1) = 0.5 or 50%
  F1 Score = 2 * 0.5 * 0.5 / (0.5 + 0.5) = 0.5 or 50%
  
entity:  Place
  TP = 2 (because San Francisco and San Diego are each correctly predicted to be a 
    Place).
  FP = 1 (because Smith is incorrectly predicted to be a Place, but is actually a 
    Person).
  FN = 1 (because Seattle is incorrectly predicted to be a Person, but is actually a 
    Place).
  Precision = 2 / (2+1) = 0.6667 or 66.67%
  Recall = 2 / (2+1) = 0.6667 or 66.67%
  F1 Score = 2 * 0.6667 * 0.6667 / (0.6667 + 0.6667) = 0.6667 or  66.67%
```

全域指標為：

全域：

```
Global:
  TP = 3 (because John Washington, San Francisco and San Diego are predicted correctly. 
    This is also the sum of all individual entity TP).
  FP = 2 (because Seattle is predicted as Person and Smith is predicted as Place. This 
    is the sum of all individual entity FP).
  FN = 2 (because Seattle is predicted as Person and Smith is predicted as Place. This 
    is the sum of all individual FN).
  Global Precision = 3 / (3+2) = 0.6 or 60%  
    (Global Precision = Global TP / (Global TP + Global FP))
  Global Recall = 3 / (3+2) = 0.6 or 60% 
    (Global Recall = Global TP / (Global TP + Global FN))
  Global F1Score = 2 * 0.6 * 0.6 / (0.6 + 0.6) = 0.6 or 60% 
    (Global F1Score = 2 * Global Precision *  Global Recall / (Global Precision + 
    Global Recall))
```



## 改善自訂實體辨識器效能
<a name="cer-performance"></a>

這些指標可讓您深入了解訓練模型使用它來識別實體時，其執行的準確度。如果指標低於您的預期，您可以使用以下幾個選項來改善指標：

1. 視您使用的是 [註釋](cer-annotation.md)或 而定[實體清單 （僅限純文字）](cer-entity-list.md)，請務必遵循個別文件中的指導方針來改善資料品質。如果您在改善資料並重新訓練模型後觀察到更好的指標，您可以繼續反覆運算並改善資料品質，以實現更好的模型效能。

1. 如果您使用的是實體清單，請考慮改用註釋。手動註釋通常可以改善您的結果。

1. 如果您確定沒有資料品質問題，但指標仍然不合理，請提交支援請求。