<｜begin▁of▁sentence｜>### Instruction:
Given the Condensed matter collaborations 2005 graph stored in a GML file named cond-mat-2005.gml, can you use the 'em' function in cdlib to perform community detection? How can you obtain a JSON representation of the detected communities?
### Response:
import networkx as nx
from cdlib import algorithms

# Create a graph from the Condensed matter collaborations 2005 dataset
G = nx.read_gml('cond-mat-2005.gml')

# Apply the Expectation-Maximization algorithm for community detection
# Assuming we want to find k communities
k = 3
communities = algorithms.em(G, k=k)

# Get the JSON representation of the detected communities
communities_json = communities.to_json()

print(communities_json)
<|EOT|>
