cyclonedx.model.model_card ========================== .. py:module:: cyclonedx.model.model_card .. autoapi-nested-parse:: This set of classes represents the model card types in the CycloneDX standard. .. note:: Introduced in CycloneDX v1.5. Environmental considerations were added in v1.6. .. note:: See the CycloneDX Schema for model cards: - XML: https://cyclonedx.org/docs/1.7/xml/#type_modelCardType - JSON: https://cyclonedx.org/docs/1.7/json/#components_items_modelCard Classes ------- .. autoapisummary:: cyclonedx.model.model_card.Co2MeasureUnit cyclonedx.model.model_card.EnergyMeasureUnit cyclonedx.model.model_card.MachineLearningApproach cyclonedx.model.model_card.Approach cyclonedx.model.model_card.InputOutputMLParameters cyclonedx.model.model_card.ModelParameters cyclonedx.model.model_card.ConfidenceInterval cyclonedx.model.model_card.PerformanceMetric cyclonedx.model.model_card.Graphic cyclonedx.model.model_card.GraphicsCollection cyclonedx.model.model_card.QuantitativeAnalysis cyclonedx.model.model_card.EthicalConsideration cyclonedx.model.model_card.FairnessAssessment cyclonedx.model.model_card.EnvironmentalConsiderations cyclonedx.model.model_card.EnergyActivity cyclonedx.model.model_card.EnergyMeasure cyclonedx.model.model_card.Co2Measure cyclonedx.model.model_card.EnergySource cyclonedx.model.model_card.EnergyProvider cyclonedx.model.model_card.EnergyConsumption cyclonedx.model.model_card.Considerations cyclonedx.model.model_card.ModelCard Module Contents --------------- .. py:class:: Co2MeasureUnit Bases: :py:obj:`str`, :py:obj:`enum.Enum` Unit of CO2. Currently only tCO2eq is defined by CycloneDX 1.6+. .. py:attribute:: TCO2EQ :value: 'tCO2eq' .. py:class:: EnergyMeasureUnit Bases: :py:obj:`str`, :py:obj:`enum.Enum` Unit of energy. Currently only kWh is defined by CycloneDX 1.6+. .. py:attribute:: KWH :value: 'kWh' .. py:class:: MachineLearningApproach Bases: :py:obj:`str`, :py:obj:`enum.Enum` Enumeration for `machineLearningApproachType`. Values are stable across 1.5–1.7. .. py:attribute:: SUPERVISED :value: 'supervised' .. py:attribute:: UNSUPERVISED :value: 'unsupervised' .. py:attribute:: REINFORCEMENT_LEARNING :value: 'reinforcement-learning' .. py:attribute:: SEMI_SUPERVISED :value: 'semi-supervised' .. py:attribute:: SELF_SUPERVISED :value: 'self-supervised' .. py:class:: Approach(*, type: Optional[MachineLearningApproach] = None) Container for the `approach` element within `modelParameters`. .. py:property:: type :type: Optional[MachineLearningApproach] Learning types describing the learning problem or hybrid learning problem. Returns: `MachineLearningApproach` if set else `None` .. py:class:: InputOutputMLParameters(*, format: str) Definition for items under `modelParameters.inputs[]` and `outputs[]`. .. py:property:: format :type: str The data format for input/output to the model. Returns: `str` .. py:class:: ModelParameters(*, approach: Optional[Approach] = None, task: Optional[str] = None, architecture_family: Optional[str] = None, model_architecture: Optional[str] = None, datasets: Optional[collections.abc.Iterable[Any]] = None, inputs: Optional[collections.abc.Iterable[InputOutputMLParameters]] = None, outputs: Optional[collections.abc.Iterable[InputOutputMLParameters]] = None) `modelParameters` block within `modelCard`. .. note:: `datasets` is not supported yet (see issue #913): - passing non-empty `datasets` to the constructor raises `NotImplementedError`. - `datasets` found while deserializing JSON/XML are ignored, so re-serializing such a BOM drops them. .. note:: `inputs` and `outputs` keep their given order and duplicates, because the position of an input/output is meaningful for a model signature. .. py:property:: approach :type: Optional[Approach] The overall approach to learning used by the model for problem solving. Returns: `Approach` if set else `None` .. py:property:: task :type: Optional[str] Directly influences the input and/or output. Examples include classification, regression, clustering, etc. Returns: `str` if set else `None` .. py:property:: architecture_family :type: Optional[str] The model architecture family such as transformer network, convolutional neural network, residual neural network, LSTM neural network, etc. Returns: `str` if set else `None` .. py:property:: model_architecture :type: Optional[str] The specific architecture of the model such as GPT-1, ResNet-50, YOLOv3, etc. Returns: `str` if set else `None` .. py:property:: inputs :type: List[InputOutputMLParameters] The input format(s) of the model, in the given order. Returns: List of `InputOutputMLParameters` .. py:property:: outputs :type: List[InputOutputMLParameters] The output format(s) from the model, in the given order. Returns: List of `InputOutputMLParameters` .. py:class:: ConfidenceInterval(*, lower_bound: Optional[str] = None, upper_bound: Optional[str] = None) Confidence interval with lower/upper bounds. .. py:property:: lower_bound :type: Optional[str] The lower bound of the confidence interval. Returns: `str` if set else `None` .. py:property:: upper_bound :type: Optional[str] The upper bound of the confidence interval. Returns: `str` if set else `None` .. py:class:: PerformanceMetric(*, type: Optional[str] = None, value: Optional[str] = None, slice_: Optional[str] = None, confidence_interval: Optional[ConfidenceInterval] = None) A single performance metric entry. .. py:property:: type :type: Optional[str] The type of performance metric. Returns: `str` if set else `None` .. py:property:: value :type: Optional[str] The value of the performance metric. Returns: `str` if set else `None` .. py:property:: slice_ :type: Optional[str] The name of the slice this metric was computed on. By default, assume this metric is not sliced. Returns: `str` if set else `None` .. py:property:: confidence_interval :type: Optional[ConfidenceInterval] The confidence interval of the metric. Returns: `ConfidenceInterval` if set else `None` .. py:class:: Graphic(*, name: Optional[str] = None, image: Optional[cyclonedx.model.AttachedText] = None) Graphic entry with optional name and image (AttachedText). .. py:property:: name :type: Optional[str] The name of the graphic. Returns: `str` if set else `None` .. py:property:: image :type: Optional[cyclonedx.model.AttachedText] The graphic (vector or raster). Base64 encoding must be specified for binary images. Returns: `AttachedText` if set else `None` .. py:class:: GraphicsCollection(*, description: Optional[str] = None, collection: Optional[collections.abc.Iterable[Graphic]] = None) A collection of graphics with optional description. .. py:property:: description :type: Optional[str] A description of this collection of graphics. Returns: `str` if set else `None` .. py:property:: collection :type: SortedSet[Graphic] A collection of graphics. Returns: Set of `Graphic` .. py:class:: QuantitativeAnalysis(*, performance_metrics: Optional[collections.abc.Iterable[PerformanceMetric]] = None, graphics: Optional[GraphicsCollection] = None) `quantitativeAnalysis` block within `modelCard`. .. py:property:: performance_metrics :type: SortedSet[PerformanceMetric] The model performance metrics being reported. Examples may include accuracy, F1 score, precision, top-3 error rates, MSC, etc. Returns: Set of `PerformanceMetric` .. py:property:: graphics :type: Optional[GraphicsCollection] A collection of graphics that represent various measurements. Returns: `GraphicsCollection` if set else `None` .. py:class:: EthicalConsideration(*, name: Optional[str] = None, mitigation_strategy: Optional[str] = None) Entry in `ethicalConsiderations` with name and mitigation strategy. .. py:property:: name :type: Optional[str] The name of the risk. Returns: `str` if set else `None` .. py:property:: mitigation_strategy :type: Optional[str] Strategy used to address this risk. Returns: `str` if set else `None` .. py:class:: FairnessAssessment(*, group_at_risk: Optional[str] = None, benefits: Optional[str] = None, harms: Optional[str] = None, mitigation_strategy: Optional[str] = None) Entry in `fairnessAssessments`. .. py:property:: group_at_risk :type: Optional[str] The groups or individuals at risk of being systematically disadvantaged by the model. Returns: `str` if set else `None` .. py:property:: benefits :type: Optional[str] Expected benefits to the identified groups. Returns: `str` if set else `None` .. py:property:: harms :type: Optional[str] Expected harms to the identified groups. Returns: `str` if set else `None` .. py:property:: mitigation_strategy :type: Optional[str] With respect to the benefits and harms outlined, any mitigation strategy implemented. Returns: `str` if set else `None` .. py:class:: EnvironmentalConsiderations(*, energy_consumptions: Optional[collections.abc.Iterable[EnergyConsumption]] = None, properties: Optional[collections.abc.Iterable[cyclonedx.model.Property]] = None) Environmental considerations (1.6+). Energy consumptions and properties. .. py:property:: energy_consumptions :type: SortedSet[EnergyConsumption] Describes energy consumption information incurred for one or more component lifecycle activities. Returns: Set of `EnergyConsumption` .. py:property:: properties :type: SortedSet[Property] Provides the ability to document properties in a name-value store. Returns: Set of `Property` .. py:class:: EnergyActivity Bases: :py:obj:`str`, :py:obj:`enum.Enum` Enumeration for lifecycle activity in `energyConsumption.activity` (1.6+). .. py:attribute:: DESIGN :value: 'design' .. py:attribute:: DATA_COLLECTION :value: 'data-collection' .. py:attribute:: DATA_PREPARATION :value: 'data-preparation' .. py:attribute:: TRAINING :value: 'training' .. py:attribute:: FINE_TUNING :value: 'fine-tuning' .. py:attribute:: VALIDATION :value: 'validation' .. py:attribute:: DEPLOYMENT :value: 'deployment' .. py:attribute:: INFERENCE :value: 'inference' .. py:attribute:: OTHER :value: 'other' .. py:class:: EnergyMeasure(*, value: float, unit: EnergyMeasureUnit = EnergyMeasureUnit.KWH) A measure of energy. Schema `energyMeasure` (1.6+): value + unit (kWh). .. py:property:: value :type: float Quantity of energy. Returns: `float` .. py:property:: unit :type: EnergyMeasureUnit Unit of energy. Returns: `EnergyMeasureUnit` .. py:class:: Co2Measure(*, value: float, unit: Co2MeasureUnit = Co2MeasureUnit.TCO2EQ) A measure of CO2. Schema `co2Measure` (1.6+): value + unit (tCO2eq). .. py:property:: value :type: float Quantity of carbon dioxide (CO2). Returns: `float` .. py:property:: unit :type: Co2MeasureUnit Unit of carbon dioxide (CO2). Returns: `Co2MeasureUnit` .. py:class:: EnergySource Bases: :py:obj:`str`, :py:obj:`enum.Enum` Enumeration for provider `energySource` (1.6+). .. py:attribute:: COAL :value: 'coal' .. py:attribute:: OIL :value: 'oil' .. py:attribute:: NATURAL_GAS :value: 'natural-gas' .. py:attribute:: NUCLEAR :value: 'nuclear' .. py:attribute:: WIND :value: 'wind' .. py:attribute:: SOLAR :value: 'solar' .. py:attribute:: GEOTHERMAL :value: 'geothermal' .. py:attribute:: HYDROPOWER :value: 'hydropower' .. py:attribute:: BIOFUEL :value: 'biofuel' .. py:attribute:: UNKNOWN :value: 'unknown' .. py:attribute:: OTHER :value: 'other' .. py:class:: EnergyProvider(*, organization: cyclonedx.model.contact.OrganizationalEntity, energy_source: EnergySource, energy_provided: EnergyMeasure, bom_ref: Optional[Union[str, cyclonedx.model.bom_ref.BomRef]] = None, description: Optional[str] = None, external_references: Optional[collections.abc.Iterable[cyclonedx.model.ExternalReference]] = None) Energy provider per schema `energyProvider` (1.6+). .. py:property:: description :type: Optional[str] A description of the energy provider. Returns: `str` if set else `None` .. py:property:: organization :type: cyclonedx.model.contact.OrganizationalEntity The organization that provides energy. Returns: `OrganizationalEntity` .. py:property:: energy_source :type: EnergySource The energy source for the energy provider. Returns: `EnergySource` .. py:property:: energy_provided :type: EnergyMeasure The energy provided by the energy source for an associated activity. Returns: `EnergyMeasure` .. py:property:: external_references :type: SortedSet[ExternalReference] External references provide a way to document systems, sites, and information that may be relevant but are not included with the BOM. Returns: Set of `ExternalReference` .. py:property:: bom_ref :type: cyclonedx.model.bom_ref.BomRef An identifier which can be used to reference the energy provider elsewhere in the BOM. Every `bom-ref` must be unique within the BOM. Returns: `BomRef` .. py:class:: EnergyConsumption(*, activity: EnergyActivity, energy_providers: collections.abc.Iterable[EnergyProvider], activity_energy_cost: EnergyMeasure, co2_cost_equivalent: Optional[Co2Measure] = None, co2_cost_offset: Optional[Co2Measure] = None, properties: Optional[collections.abc.Iterable[cyclonedx.model.Property]] = None) Energy consumption entry. Matches schema `energyConsumption` (1.6+). .. py:property:: activity :type: EnergyActivity The type of activity that is part of a machine learning model development or operational lifecycle. Returns: `EnergyActivity` .. py:property:: energy_providers :type: SortedSet[EnergyProvider] The provider(s) of the energy consumed by the associated model development lifecycle activity. Returns: Set of `EnergyProvider` .. py:property:: activity_energy_cost :type: EnergyMeasure The total energy cost associated with the model lifecycle activity. Returns: `EnergyMeasure` .. py:property:: co2_cost_equivalent :type: Optional[Co2Measure] The CO2 cost (debit) equivalent to the total energy cost. Returns: `Co2Measure` if set else `None` .. py:property:: co2_cost_offset :type: Optional[Co2Measure] The CO2 offset (credit) for the CO2 equivalent cost. Returns: `Co2Measure` if set else `None` .. py:property:: properties :type: SortedSet[Property] Provides the ability to document properties in a name-value store. Returns: Set of `Property` .. py:class:: Considerations(*, users: Optional[collections.abc.Iterable[str]] = None, use_cases: Optional[collections.abc.Iterable[str]] = None, technical_limitations: Optional[collections.abc.Iterable[str]] = None, performance_tradeoffs: Optional[collections.abc.Iterable[str]] = None, ethical_considerations: Optional[collections.abc.Iterable[EthicalConsideration]] = None, environmental_considerations: Optional[EnvironmentalConsiderations] = None, fairness_assessments: Optional[collections.abc.Iterable[FairnessAssessment]] = None) `considerations` block within `modelCard`. .. py:property:: users :type: SortedSet[str] Who are the intended users of the model? Returns: Set of `str` .. py:property:: use_cases :type: SortedSet[str] What are the intended use cases of the model? Returns: Set of `str` .. py:property:: technical_limitations :type: SortedSet[str] What are the known technical limitations of the model? E.g. What kind(s) of data should the model be expected not to perform well on? What are the factors that might degrade model performance? Returns: Set of `str` .. py:property:: performance_tradeoffs :type: SortedSet[str] What are the known tradeoffs in accuracy/performance of the model? Returns: Set of `str` .. py:property:: ethical_considerations :type: SortedSet[EthicalConsideration] What are the ethical risks involved in the application of this model? Returns: Set of `EthicalConsideration` .. py:property:: environmental_considerations :type: Optional[EnvironmentalConsiderations] What are the various environmental impacts the corresponding machine learning model has exhibited across its lifecycle? Returns: `EnvironmentalConsiderations` if set else `None` .. py:property:: fairness_assessments :type: SortedSet[FairnessAssessment] How does the model affect groups at risk of being systematically disadvantaged? What are the harms and benefits to the various affected groups? Returns: Set of `FairnessAssessment` .. py:class:: ModelCard(*, bom_ref: Optional[Union[str, cyclonedx.model.bom_ref.BomRef]] = None, model_parameters: Optional[ModelParameters] = None, quantitative_analysis: Optional[QuantitativeAnalysis] = None, considerations: Optional[Considerations] = None, properties: Optional[collections.abc.Iterable[cyclonedx.model.Property]] = None) Internal representation of CycloneDX `modelCardType`. Version gating: - Introduced in schema 1.5 - Unchanged structurally in 1.6 except for additional nested environmental considerations inside `considerations` - 1.7 retains 1.6 structure (additions in nested types only) .. py:property:: model_parameters :type: Optional[ModelParameters] Hyper-parameters for construction of the model. Returns: `ModelParameters` if set else `None` .. py:property:: quantitative_analysis :type: Optional[QuantitativeAnalysis] A quantitative analysis of the model. Returns: `QuantitativeAnalysis` if set else `None` .. py:property:: considerations :type: Optional[Considerations] What considerations should be taken into account regarding the model's construction, training, and application? Returns: `Considerations` if set else `None` .. py:property:: properties :type: SortedSet[Property] Provides the ability to document properties in a name-value store. Returns: Set of `Property` .. py:property:: bom_ref :type: cyclonedx.model.bom_ref.BomRef An identifier which can be used to reference the model card elsewhere in the BOM. Every `bom-ref` must be unique within the BOM. Returns: `BomRef`