{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SageMaker.Types.ClarifyTextConfig
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SageMaker.Types.ClarifyTextConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.SageMaker.Types.ClarifyTextGranularity
import Amazonka.SageMaker.Types.ClarifyTextLanguage

-- | A parameter used to configure the SageMaker Clarify explainer to treat
-- text features as text so that explanations are provided for individual
-- units of text. Required only for natural language processing (NLP)
-- explainability.
--
-- /See:/ 'newClarifyTextConfig' smart constructor.
data ClarifyTextConfig = ClarifyTextConfig'
  { -- | Specifies the language of the text features in
    -- <%20https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ISO 639-1> or
    -- <https://en.wikipedia.org/wiki/ISO_639-3 ISO 639-3> code of a supported
    -- language.
    --
    -- For a mix of multiple languages, use code @\'xx\'@.
    ClarifyTextConfig -> ClarifyTextLanguage
language :: ClarifyTextLanguage,
    -- | The unit of granularity for the analysis of text features. For example,
    -- if the unit is @\'token\'@, then each token (like a word in English) of
    -- the text is treated as a feature. SHAP values are computed for each
    -- unit\/feature.
    ClarifyTextConfig -> ClarifyTextGranularity
granularity :: ClarifyTextGranularity
  }
  deriving (ClarifyTextConfig -> ClarifyTextConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClarifyTextConfig -> ClarifyTextConfig -> Bool
$c/= :: ClarifyTextConfig -> ClarifyTextConfig -> Bool
== :: ClarifyTextConfig -> ClarifyTextConfig -> Bool
$c== :: ClarifyTextConfig -> ClarifyTextConfig -> Bool
Prelude.Eq, ReadPrec [ClarifyTextConfig]
ReadPrec ClarifyTextConfig
Int -> ReadS ClarifyTextConfig
ReadS [ClarifyTextConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ClarifyTextConfig]
$creadListPrec :: ReadPrec [ClarifyTextConfig]
readPrec :: ReadPrec ClarifyTextConfig
$creadPrec :: ReadPrec ClarifyTextConfig
readList :: ReadS [ClarifyTextConfig]
$creadList :: ReadS [ClarifyTextConfig]
readsPrec :: Int -> ReadS ClarifyTextConfig
$creadsPrec :: Int -> ReadS ClarifyTextConfig
Prelude.Read, Int -> ClarifyTextConfig -> ShowS
[ClarifyTextConfig] -> ShowS
ClarifyTextConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClarifyTextConfig] -> ShowS
$cshowList :: [ClarifyTextConfig] -> ShowS
show :: ClarifyTextConfig -> String
$cshow :: ClarifyTextConfig -> String
showsPrec :: Int -> ClarifyTextConfig -> ShowS
$cshowsPrec :: Int -> ClarifyTextConfig -> ShowS
Prelude.Show, forall x. Rep ClarifyTextConfig x -> ClarifyTextConfig
forall x. ClarifyTextConfig -> Rep ClarifyTextConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ClarifyTextConfig x -> ClarifyTextConfig
$cfrom :: forall x. ClarifyTextConfig -> Rep ClarifyTextConfig x
Prelude.Generic)

-- |
-- Create a value of 'ClarifyTextConfig' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'language', 'clarifyTextConfig_language' - Specifies the language of the text features in
-- <%20https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ISO 639-1> or
-- <https://en.wikipedia.org/wiki/ISO_639-3 ISO 639-3> code of a supported
-- language.
--
-- For a mix of multiple languages, use code @\'xx\'@.
--
-- 'granularity', 'clarifyTextConfig_granularity' - The unit of granularity for the analysis of text features. For example,
-- if the unit is @\'token\'@, then each token (like a word in English) of
-- the text is treated as a feature. SHAP values are computed for each
-- unit\/feature.
newClarifyTextConfig ::
  -- | 'language'
  ClarifyTextLanguage ->
  -- | 'granularity'
  ClarifyTextGranularity ->
  ClarifyTextConfig
newClarifyTextConfig :: ClarifyTextLanguage -> ClarifyTextGranularity -> ClarifyTextConfig
newClarifyTextConfig ClarifyTextLanguage
pLanguage_ ClarifyTextGranularity
pGranularity_ =
  ClarifyTextConfig'
    { $sel:language:ClarifyTextConfig' :: ClarifyTextLanguage
language = ClarifyTextLanguage
pLanguage_,
      $sel:granularity:ClarifyTextConfig' :: ClarifyTextGranularity
granularity = ClarifyTextGranularity
pGranularity_
    }

-- | Specifies the language of the text features in
-- <%20https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ISO 639-1> or
-- <https://en.wikipedia.org/wiki/ISO_639-3 ISO 639-3> code of a supported
-- language.
--
-- For a mix of multiple languages, use code @\'xx\'@.
clarifyTextConfig_language :: Lens.Lens' ClarifyTextConfig ClarifyTextLanguage
clarifyTextConfig_language :: Lens' ClarifyTextConfig ClarifyTextLanguage
clarifyTextConfig_language = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ClarifyTextConfig' {ClarifyTextLanguage
language :: ClarifyTextLanguage
$sel:language:ClarifyTextConfig' :: ClarifyTextConfig -> ClarifyTextLanguage
language} -> ClarifyTextLanguage
language) (\s :: ClarifyTextConfig
s@ClarifyTextConfig' {} ClarifyTextLanguage
a -> ClarifyTextConfig
s {$sel:language:ClarifyTextConfig' :: ClarifyTextLanguage
language = ClarifyTextLanguage
a} :: ClarifyTextConfig)

-- | The unit of granularity for the analysis of text features. For example,
-- if the unit is @\'token\'@, then each token (like a word in English) of
-- the text is treated as a feature. SHAP values are computed for each
-- unit\/feature.
clarifyTextConfig_granularity :: Lens.Lens' ClarifyTextConfig ClarifyTextGranularity
clarifyTextConfig_granularity :: Lens' ClarifyTextConfig ClarifyTextGranularity
clarifyTextConfig_granularity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ClarifyTextConfig' {ClarifyTextGranularity
granularity :: ClarifyTextGranularity
$sel:granularity:ClarifyTextConfig' :: ClarifyTextConfig -> ClarifyTextGranularity
granularity} -> ClarifyTextGranularity
granularity) (\s :: ClarifyTextConfig
s@ClarifyTextConfig' {} ClarifyTextGranularity
a -> ClarifyTextConfig
s {$sel:granularity:ClarifyTextConfig' :: ClarifyTextGranularity
granularity = ClarifyTextGranularity
a} :: ClarifyTextConfig)

instance Data.FromJSON ClarifyTextConfig where
  parseJSON :: Value -> Parser ClarifyTextConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ClarifyTextConfig"
      ( \Object
x ->
          ClarifyTextLanguage -> ClarifyTextGranularity -> ClarifyTextConfig
ClarifyTextConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Language")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Granularity")
      )

instance Prelude.Hashable ClarifyTextConfig where
  hashWithSalt :: Int -> ClarifyTextConfig -> Int
hashWithSalt Int
_salt ClarifyTextConfig' {ClarifyTextGranularity
ClarifyTextLanguage
granularity :: ClarifyTextGranularity
language :: ClarifyTextLanguage
$sel:granularity:ClarifyTextConfig' :: ClarifyTextConfig -> ClarifyTextGranularity
$sel:language:ClarifyTextConfig' :: ClarifyTextConfig -> ClarifyTextLanguage
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ClarifyTextLanguage
language
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ClarifyTextGranularity
granularity

instance Prelude.NFData ClarifyTextConfig where
  rnf :: ClarifyTextConfig -> ()
rnf ClarifyTextConfig' {ClarifyTextGranularity
ClarifyTextLanguage
granularity :: ClarifyTextGranularity
language :: ClarifyTextLanguage
$sel:granularity:ClarifyTextConfig' :: ClarifyTextConfig -> ClarifyTextGranularity
$sel:language:ClarifyTextConfig' :: ClarifyTextConfig -> ClarifyTextLanguage
..} =
    forall a. NFData a => a -> ()
Prelude.rnf ClarifyTextLanguage
language
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ClarifyTextGranularity
granularity

instance Data.ToJSON ClarifyTextConfig where
  toJSON :: ClarifyTextConfig -> Value
toJSON ClarifyTextConfig' {ClarifyTextGranularity
ClarifyTextLanguage
granularity :: ClarifyTextGranularity
language :: ClarifyTextLanguage
$sel:granularity:ClarifyTextConfig' :: ClarifyTextConfig -> ClarifyTextGranularity
$sel:language:ClarifyTextConfig' :: ClarifyTextConfig -> ClarifyTextLanguage
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Language" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ClarifyTextLanguage
language),
            forall a. a -> Maybe a
Prelude.Just (Key
"Granularity" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ClarifyTextGranularity
granularity)
          ]
      )