1 of 74

Google’s Gemini API

Brochure

Incidencia de la inteligencia artificial en la composición musical

Sebastian Gomez

he/him

GDE in Web Technologies

2 of 74

  • Ingeniero de Sistemas e Informática con Maestría en Ingeniería de Sistemas.
  • Engineering Manager en Twilio.
  • Escritor en mi propio blog, www.sebastian-gomez.com
  • Estudiante de música.
  • Explorando la composición musical para cine y escenarios diversos.
  • Buscando soluciones creativas sin necesidad de componer directamente.

3 of 74

10 years ago …

4 of 74

5 of 74

¿Qué es IA generativa?

6 of 74

¿Qué es un LLM?

[...]

[...]

[...]

[...]

0.02

0.03

0.9

0.01

0.0

Dogs

Rain

Drops

Fish

Wind

and

cats

raining

It’s

7 of 74

Las rosas son rojas,

Violets are blue,

Sugar is sweet,

8 of 74

Las rosas son rojas,

Las violetas son azules,

El azucar es dulce,

9 of 74

for(var i = 0

10 of 74

for(var i = 0; i < 10; i++) {

11 of 74

Los LLMs modernos�son enormes

12 of 74

Entity extraction

Classification

Summarization

Classic Natural Language Problems

Sentiment Analysis

Translation

13 of 74

Los LLMs nos permiten crear prototipos rápidamente

14 of 74

Explain this joke: “Solía ​​ser adicto al jabón, pero ahora estoy limpio.

El chiste es un juego de palabras con la palabra "limpio". Tiene dos significados:

  1. Estar libre de suciedad u otras sustancias no deseadas.
  2. Estar libre de adicción.

User

Model

El chiste es divertido porque es inesperado. El oyente espera que el hablante esté hablando sobre el primer significado de "limpio", pero en realidad está hablando sobre el segundo significado. Esto crea una sorpresa y provoca una risa.

15 of 74

  1. Construir un volcán.

  • Hacer un horno solar.

  • Crear una impresora 3D.

  • Construir un robot.

  • Diseñar un sistema de filtración de agua.

Dame cinco buenas ideas para proyectos de feria de ciencias.

User

Model

16 of 74

Search

Conversation

Content generation

Los LLMs se caracterizan por habilidades emergentes, o la capacidad de realizar tareas que no estaban presentes en modelos más pequeños.

La comprensión contextual del lenguaje humano por parte de los LLMs cambia la forma en que interactuamos con los datos y los sistemas inteligentes.

Los LLMs pueden encontrar patrones y conexiones en grandes y dispares corpus de datos.

¿Por qué los LLMs son tan diferentes?

17 of 74

Google el pionero de la industria del AI

Responsible AI

3,000

Researchers

7,000

Publications

Built & Tested for Safety

Privacy in design

Upholds high scientific standards

Accountable to People

Socially Beneficial

Avoid creating unfair bias

2015

Google DeepMind AlphaGo defeats Go champion

2016

Google’s DeepMind helps detect eye disease

2017

Google invents Transformer kickstarting LLM revolution

2018

Google’s groundbreaking large language model, BERT

2019

Text-to-Text

Transfer Transformer

LLM 10B P Model Open Sourced

2020

Google LaMDA

Model Trained to converse

2022

AlphaFold predicts structures of all known proteins

2023

A conversational AI Service powered by PaLM2

2024

Family of multimodal LLMs & products

18 of 74

Multimodalidad

Transformer

Image

Decoder

Text

Decoder

19 of 74

20 of 74

(Android AICore)

21 of 74

22 of 74

ai.google.dev/gemma

23 of 74

For Developers

For Consumers

For Business and Enterprise

Models

Gemini API �(in Google AI Studio + ai.google.dev)

Gemini for Google Workspace

Gemini for Google Cloud

Gemini in Vertex AI

Gemini | app and web

Gemini in the Google App

Gemini in Gmails, Docs…

Sobre lo que es esta presentación

El ecosistema de Gemini

La más avanzada inteligencia artificial de Google

24 of 74

Empezando con Gemini API

25 of 74

  • Generar claves API
  • Crear, probar y guardar prompts
  • Personalizar modelos en minutos
  • Generar código inicial
  • Comprender el uso de tokens

26 of 74

27 of 74

28 of 74

29 of 74

30 of 74

31 of 74

  • El token es la unidad de datos utilizada por Gemini.
  • Para Gemini, un token es aproximadamente 4 caracteres.
  • Una ventana de contexto consiste en:
    • Todos los tokens de entrada procesados por Gemini.
    • Todos los tokens de salida generados por Gemini.
    • Para entender tu uso, puedes utilizar el método count_tokens() (gratuito o de pago).

Entendiendo los token

32 of 74

import google.generativeai as genai

model = genai.GenerativeModel('models/gemini-1.5-flash')

resp = model.generate_content(

'Write the first paragraph of a story about a magic backpack')

>>> print(resp.text)

In a bustling city, amidst the vibrant tapestry of human existence, there existed a peculiar entity named Archie. Archie, however, was no ordinary backpack…

�>>> resp.usage_metadata

prompt_token_count: 11

candidate_token_count: 123

33 of 74

34 of 74

REST API + Client libraries for:

Python, Node, Swift, Java, Go, Flutter and Dart

35 of 74

Vertex AI

Enterprise grade support.

Full MLOps (Examples: Model evaluation, monitoring, registry)

Vertex AI

Check it out when you're

ready for production

Gemini API and Vertex AI

Both give access Gemini family of models.

Vertex AI

36 of 74

Patrones de uso

37 of 74

  • Versión más pequeña de Gemini
  • Optimizada para tareas de alta frecuencia
  • La variante más rápida de Gemini
  • Costo más bajo que Gemini 1.5 Pro

Gemini 1.5 Flash

38 of 74

Prompting

Básico

39 of 74

Escribe un poema sobre una mochila mágica

In a world of wonder, behold,

A backpack with tales yet untold.

Its fabric shimmers, alive with might,

A portal to realms, day and night.

40 of 74

Escribe un poema sobre una mochila mágica

Una mochila mágica, de piel y hebilla de plata,

guarda en su interior secretos que nunca se revelarán.

Un universo infinito en su espacio diminuto,

donde las estrellas brillan y los sueños se perpetúan.

...

41 of 74

Genere un breve tip sobre JavaScript. Los buenos tips son breves y contienen un ejemplo de código que muestra el consejo.

**Tip: Use Array.prototype.flat() to flatten an array of arrays.**

```javascript

const array = [[1, 2], [3, 4], [5, 6]];

console.log(array.flat());

// Output: [1, 2, 3, 4, 5, 6]

```

42 of 74

## Consejo rápido: Usa el operador de cortocircuito `&&` para condiciones condicionales.

Puedes simplificar tu código utilizando el operador `&&` para ejecutar una acción solo si una condición es verdadera.

```javascript

// Sin operador de cortocircuito

let message = "";

if (user) {

message = `Hola ${user.name}!`;

}

// Con operador de cortocircuito

let message = user && `Hola ${user.name}!`;

```

Este consejo es útil para evitar código repetitivo y mantener tu código limpio y conciso. ¡Intenta usarlo en tus proyectos!

```

43 of 74

Genere un breve tip sobre JavaScript. Los buenos tips son breves y contienen un ejemplo de código que muestra el consejo.

topic: let and const

tip: Prefiera usar `let` y `const` para inicializar variables, en lugar de `var`, ya que `var` no tiene alcance de bloque ni protección contra mutabilidad.

p.ej. const miVar = "EJEMPLO";

topic: arrow syntax

tip:

44 of 74

45 of 74

import google.generativeai as genai

model = genai.GenerativeModel('models/gemini-1.5-flash')

resp = model.generate_content(

'Write the first paragraph of a story about a magic backpack')

>>> print(resp.text)

In a bustling city, amidst the vibrant tapestry of human existence, there existed a peculiar entity named Archie. Archie, however, was no ordinary backpack...

46 of 74

chat = model.start_chat()

response = chat.send_message(

"Hello, what should I have for dinner?")

print(response.text)

# 'Here are some suggestions...'

response = chat.send_message(

"How do I cook the first one?")

47 of 74

Contents

Settings/Configs

Text

Text

Text

Tools

Tools

Safety Settings

Safety Settings

Generation Config

Content of role: "user" �containing multimodal Parts:

Content of role: "model"

"user" content: a text Part

Tools specified by the caller

Safety setting configured by caller

Generation Config includes: temperature, Top P, Top K, stop seq, max output tokens etc.

Generate Content Request

48 of 74

Generate Content Request

Candidate(s)

Feedback

Text

Block Reason

Safety Ratings

Candidate "Content"�note: only one candidate returned today

why the model stopped generating

feedback on the prompt

Finish Reason

Finish Message

set if finish reason is present

Safety Ratings

Safety Ratings

how safe is the response

49 of 74

Haz un plan y luego ejecutalo

Few shot prompts.

Prompts Encadenados

Contexto

Temperature, Safety settings, Top-P, Top-K.

Parámetros de Generación

50 of 74

Generación de Música

Enfoque de composición de música a partir de la teoría musical

51 of 74

Convertir el lenguaje del usuario en lenguaje de máquina que genere música

Podría ayudar a los compositores a generar ideas

Generar música basado en un prompt del usuario

Generación de música

52 of 74

Decisión #1

  • ¿Qué lenguaje de notación musical escogeré?

53 of 74

Decisión #1

  • ¿Qué lenguaje de notación musical escogeré?

54 of 74

55 of 74

Decisión #2

  • ¿Como le enseño al modelo que es ABC Music Notation?

56 of 74

57 of 74

58 of 74

Decisión #3

  • ¿Como entreno al modelo en composición?

59 of 74

60 of 74

Tuning

61 of 74

Tuning

  • In AI Studio

62 of 74

63 of 74

64 of 74

65 of 74

66 of 74

67 of 74

Veamos los resultados

68 of 74

Composición #1

Context: You are a skilled composer specializing in creating harmonized melodies in ABC notation. Your compositions typically consist of four voices: two for the melody and two for the bass, without any chord annotations. You adhere to the principles of tonal music, ensuring that each melody is simple yet harmonically rich and well-structured.

Input: Compose a four-part melody in the key of C# minor, set in 4/4 time. The melody should evoke a deep sense of melancholy and sadness, reflecting the somber emotional tone of the piece. Ensure that no chord annotations are included in the notation.

69 of 74

Composición #2

Context: You are a skilled composer specializing in creating harmonized melodies in ABC notation. Your compositions typically consist of four voices: two for the melody and two for the bass, without any chord annotations. You adhere to the principles of tonal music, ensuring that each melody is simple yet harmonically rich and well-structured.�Input: Compose a two-part melody in the key of G major, set in 2/4 time. The melody should evoke a party and happiness. Ensure that no chord annotations are included in the notation.

T:Party Time!�M:2/4�L:1/8�K:G�V:1 clef=treble�|: d2 e2|f2 g2|a2 g2|f2 e2|d2 c2|d2 e2:|�V:2 clef=treble�|: d3 g|g3 d |d3 g|g3 a|a3 g|g4:|

70 of 74

Composición #3

Context: You are a skilled composer specializing in creating harmonized melodies in ABC notation. Your compositions typically consist of four voices: two for the melody and two for the bass, without any chord annotations. You adhere to the principles of tonal music, ensuring that each melody is simple yet harmonically rich and well-structured.

Input: Compose a three-part melody in the key of G major, set in 3/4 time. The melody should cultivate focus and some russian style.

Model:

T:Martial Spirit

M:3/4

L:1/4

K:G

V:1 clef=treble

|:gdc|Bce|B3|Bcd|dcd|d3:|

V:2 clef=treble

|:G2A|e3|B3|c3|d3|G3:|

V:3 clef=bass

|:G,B,D|e,B,E|G,B,D|B,e,d|c,d,c|G,B,D:|

71 of 74

Composición #4

Context: You are a skilled composer specializing in creating harmonized melodies in ABC notation. Your compositions typically consist of four voices: two for the melody and two for the bass, without any chord annotations. You adhere to the principles of tonal music, ensuring that each melody is simple yet harmonically rich and well-structured.

Input: Compose a two-part melody in the key of C major, set in 3/4 time. The melody should evoke a ship in the ocean. Ensure that no chord annotations are included in the notation.

72 of 74

Composición #5

Context: You are a skilled composer specializing in creating harmonized melodies in ABC notation. Your compositions typically consist of four voices: two for the melody and two for the bass, without any chord annotations. You adhere to the principles of tonal music, ensuring that each melody is simple yet harmonically rich and well-structured.

Input: Compose a four-part melody in the key of E major, set in 3/4 time. The song should evoke courage like a battle in the mountains. ensure chord annotations are included in the notation.

73 of 74

Para más contenido ejemplos y demás

74 of 74

Muchas gracias!

Sebastian Gomez

he/him

GDE in Web Technologies