Row 4302

Row ID: 4302 | Dataset Entry | Axioma AXP Content Repository

Content Data

This page contains data entry 4302 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.

def compile(self) -> Tuple\[tf.keras.Model, Callable, List\[str\], Tuple\]:

"""

Compile all the sub-objectives into one and return the objects

for the optimisation process.

​

Returns

\-------

model\_reconfigured

Model with the outputs needed for the optimization.

objective\_function

Function to call that compute the loss for the objectives.

names

Names of each objectives.

input\_shape

Shape of the input, one sample for each optimization.

"""

\# the number of inputs will be the number of combinations possible

\# of the objectives, the mask are used to take into account

\# these combinations

nb\_sub\_objectives = len(self.multipliers)

​

\# re-arrange to match the different objectives with the model outputs

masks = np.array(\[np.array(m, dtype=object) for m in itertools.product(\*self.masks)\])

masks = \[tf.cast(tf.stack(list(masks\[:, i\])), tf.float32) for i in

range(nb\_sub\_objectives)\]

​

\# the name of each combination is the concatenation of each objectives

names = np.array(\[' & '.join(names) for names in

itertools.product(\*self.names)\])

\# one multiplier by sub-objective

multipliers = tf.constant(self.multipliers)

​

def objective\_function(model\_outputs):

loss = 0.0

for output\_index in range(0, nb\_sub\_objectives):

outputs = model\_outputs\[output\_index\]

loss += self.funcs\[output\_index\](

outputs, tf.cast(masks\[output\_index\], outputs.dtype))

loss \*= multipliers\[output\_index\]

return loss

​

\# the model outputs will be composed of the layers needed

model\_reconfigured = tf.keras.Model(self.model.input, \[\*self.layers\])

​

nb\_combinations = masks\[0\].shape\[0\]

input\_shape = (nb\_combinations, \*model\_reconfigured.input.shape\[1:\])

​

return model\_reconfigured, objective\_function, names, input\_shape

someone pls help me writing this function

FieldValue
text def compile(self) -> Tuple\[tf.keras.Model, Callable, List\[str\], Tuple\]: """ Compile all the sub-objectives into one and return the objects for the optimisation process. ​ Returns \------- model\_reconfigured Model with the outputs needed for the optimization. objective\_function Function to call that compute the loss for the objectives. names Names of each objectives. input\_shape Shape of the input, one sample for each optimization. """ \# the number of inputs will be…
label r/pytorch
dataType post
communityName r/pytorch
datetime 2024-04-07
username_encoded Z0FBQUFBQm5LakwxVjBXRzRhNjVRN3NMcElfTUdhcFZpMU5mcDA2OHB5aExFbVhyOV9SeDlsMUZTUUh5UENzRUhNTXh2VEdJejdaY0lSVXQtYjd6bTJjZlVYZ1VMNnF4eWc9PQ==
url_encoded Z0FBQUFBQm5Lak9GQjVHNG1NQlZmcEhIa3hqMEZmQ29rdEczTGNNX3g5OFUtR3Uzd2lLRlZmRTB1M1lmaGp6WWl5SjJvOVgtTnVCRnhmZXhIbk9vX2l1WEFKM0t5el9uUElPMDI3czVJanl4WnptS2FsNV9adjIyenEwLTc2MWk4QU1QRGZ6SDM4VTZiS0hwbS1tUjk0azhKNGh4M25Eang0UXlRZW81WFVZdUxPSm9GVjdNRndMZTVSN1ctUTd1TG80YlNLR2FXc2lPaExRYkE0UGdwVjJ0cFl4NjdZS3hEUT09

Raw Record

{
  "text": "def compile(self) -> Tuple\\[tf.keras.Model, Callable, List\\[str\\], Tuple\\]:\n\n\"\"\"\n\nCompile all the sub-objectives into one and return the objects\n\nfor the optimisation process.\n\n​\n\nReturns\n\n\\-------\n\nmodel\\_reconfigured\n\nModel with the outputs needed for the optimization.\n\nobjective\\_function\n\nFunction to call that compute the loss for the objectives.\n\nnames\n\nNames of each objectives.\n\ninput\\_shape\n\nShape of the input, one sample for each optimization.\n\n\"\"\"\n\n\\# the number of inputs will be the number of combinations possible\n\n\\# of the objectives, the mask are used to take into account\n\n\\# these combinations\n\nnb\\_sub\\_objectives = len(self.multipliers)\n\n​\n\n\\# re-arrange to match the different objectives with the model outputs\n\nmasks = np.array(\\[np.array(m, dtype=object) for m in itertools.product(\\*self.masks)\\])\n\nmasks = \\[tf.cast(tf.stack(list(masks\\[:, i\\])), tf.float32) for i in\n\nrange(nb\\_sub\\_objectives)\\]\n\n​\n\n\\# the name of each combination is the concatenation of each objectives\n\nnames = np.array(\\[' & '.join(names) for names in\n\nitertools.product(\\*self.names)\\])\n\n\\# one multiplier by sub-objective\n\nmultipliers = tf.constant(self.multipliers)\n\n​\n\ndef objective\\_function(model\\_outputs):\n\nloss = 0.0\n\nfor output\\_index in range(0, nb\\_sub\\_objectives):\n\noutputs = model\\_outputs\\[output\\_index\\]\n\nloss += self.funcs\\[output\\_index\\](\n\noutputs, tf.cast(masks\\[output\\_index\\], outputs.dtype))\n\nloss \\*= multipliers\\[output\\_index\\]\n\nreturn loss\n\n​\n\n\\# the model outputs will be composed of the layers needed\n\nmodel\\_reconfigured = tf.keras.Model(self.model.input, \\[\\*self.layers\\])\n\n​\n\nnb\\_combinations = masks\\[0\\].shape\\[0\\]\n\ninput\\_shape = (nb\\_combinations, \\*model\\_reconfigured.input.shape\\[1:\\])\n\n​\n\nreturn model\\_reconfigured, objective\\_function, names, input\\_shape  \n\n\n  \n\n\nsomeone pls help me writing this function",
  "label": "r/pytorch",
  "dataType": "post",
  "communityName": "r/pytorch",
  "datetime": "2024-04-07",
  "username_encoded": "Z0FBQUFBQm5LakwxVjBXRzRhNjVRN3NMcElfTUdhcFZpMU5mcDA2OHB5aExFbVhyOV9SeDlsMUZTUUh5UENzRUhNTXh2VEdJejdaY0lSVXQtYjd6bTJjZlVYZ1VMNnF4eWc9PQ==",
  "url_encoded": "Z0FBQUFBQm5Lak9GQjVHNG1NQlZmcEhIa3hqMEZmQ29rdEczTGNNX3g5OFUtR3Uzd2lLRlZmRTB1M1lmaGp6WWl5SjJvOVgtTnVCRnhmZXhIbk9vX2l1WEFKM0t5el9uUElPMDI3czVJanl4WnptS2FsNV9adjIyenEwLTc2MWk4QU1QRGZ6SDM4VTZiS0hwbS1tUjk0azhKNGh4M25Eang0UXlRZW81WFVZdUxPSm9GVjdNRndMZTVSN1ctUTd1TG80YlNLR2FXc2lPaExRYkE0UGdwVjJ0cFl4NjdZS3hEUT09"
}

Entry Information