I am using Hugging Face and SageMaker - overriding defaults using the inferences.py file in the code/ directory as explained at the bottom of this page here. My output is written in formatted JSON with new lines but the newline characters are causing an error downstream. Is it possible to write the output all in one line?
Transformer code
transformer = Transformer(
model_name=step_create_model.properties.ModelName,
instance_type="ml.m5.xlarge",
instance_count=1,
output_path=output_uri
)
step_transform = TransformStep(
name="NLPTransform",
transformer=transformer,
inputs = TransformInput(
data=step_process.properties.ProcessingOutputConfig.Outputs[
"batch_input"
].S3Output.S3Uri,
),
depends_on=['NLPProcess']
)
Here’s the current output
[
{
"input": "test input",
"prediction": "other"
}
]
And here’s the desired output
[{“input”: “test input”, “prediction”: “other”}]
The output_fn below
def output_fn(preds_inputs, accept):
predictions = preds_inputs['pred']
inputs = preds_inputs['inpts']
outputs = []
for pred, inpt in zip(predictions, inputs):
outputs.append({'input': inpt, 'prediction': pred})
return outputs